Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

invoke JSONArray to Object[] error #1558

Open
aruanruan opened this issue Nov 1, 2017 · 4 comments
Open

invoke JSONArray to Object[] error #1558

aruanruan opened this issue Nov 1, 2017 · 4 comments

Comments

@aruanruan
Copy link

aruanruan commented Nov 1, 2017

my java bean define:

public class Request implements Serializable{
	private String id;
	private String instance;
	private String _interface;
	private String method;
	private Object[] params;
      public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getInstance() {
		return instance;
	}
	public void setInstance(String instance) {
		this.instance = instance;
	}
	public String getInterface() {
		return _interface;
	}
	public void setInterface(String _interface) {
		this._interface = _interface;
	}
	public String getMethod() {
		return method;
	}
	public void setMethod(String method) {
		this.method = method;
	}
	public Object[] getParams() {
		return params;
	}
	public void setParams(Object[] params) {
		this.params = params;
	}
}

my json string is:

{"id": "439a3213-e734-4bf3-9870-2c471f43d651", "instance": "v1", "interface": "com.xxx.aplan.UICommands", "method": "start", "params": ["tony"], "@type": "com.xxx.dcp.rpc.core.Request"}

but when set property 'params' throws an error because: JSONArray can not be set to params

wenshao added a commit that referenced this issue Nov 1, 2017
@wenshao
Copy link
Member

wenshao commented Nov 1, 2017

什么版本?这个问题修复过的

wenshao added a commit that referenced this issue Nov 1, 2017
@aruanruan
Copy link
Author

aruanruan commented Nov 2, 2017

版本: 1.2.39
com.alibaba.fastjson.JSONException: create instance error
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:350)
at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1335)
at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1301)
at com.alibaba.fastjson.JSON.parse(JSON.java:151)
at com.alibaba.fastjson.JSON.parse(JSON.java:161)
at com.alibaba.fastjson.JSON.parse(JSON.java:130)

出错在DefaultJSONParser.java的332行
fieldDeserializer.setValue(instance, entry.getValue());

Caused by: com.alibaba.fastjson.JSONException: set property error, params
at com.alibaba.fastjson.parser.deserializer.FieldDeserializer.setValue(FieldDeserializer.java:136)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:332)
... 46 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.alibaba.fastjson.parser.deserializer.FieldDeserializer.setValue(FieldDeserializer.java:96)

@wenshao
Copy link
Member

wenshao commented Nov 3, 2017

问题是无法重现问题,可以提一下更完整的堆栈信息么?

wenshao added a commit that referenced this issue Nov 3, 2017
@aruanruan
Copy link
Author

data:
{"id": "33c1da69-bc18-4c2e-8227-86398bef0319", "instance": "v1", "interface": "com.xxx.dcp.Echo", "method": "sayHi", "params": ["tony"], "@type": "com.xxx.dcp.rpc.core.Request"}

stack:
2017-11-04 15:44:06,626 ERROR (WebSocketFrameHandler.java:50)- unsupported frame content:
com.alibaba.fastjson.JSONException: create instance error
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:350)
at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1335)
at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1301)
at com.alibaba.fastjson.JSON.parse(JSON.java:151)
at com.alibaba.fastjson.JSON.parse(JSON.java:161)
at com.alibaba.fastjson.JSON.parse(JSON.java:130)
at com.xxx.dcp.serialize.json.FastJsonObjectInput.readObject(FastJsonObjectInput.java:103)
at com.xxx.dcp.serialize.SerializerUtils.deserialize(SerializerUtils.java:75)
at com.xxx.ate.aplan.ms.netty.WebSocketFrameHandler.channelRead0(WebSocketFrameHandler.java:38)
at com.xxx.ate.aplan.ms.netty.WebSocketFrameHandler.channelRead0(WebSocketFrameHandler.java:1)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:192)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:651)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:574)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:488)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:450)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.alibaba.fastjson.JSONException: set property error, params
at com.alibaba.fastjson.parser.deserializer.FieldDeserializer.setValue(FieldDeserializer.java:136)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:332)
... 46 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.alibaba.fastjson.parser.deserializer.FieldDeserializer.setValue(FieldDeserializer.java:96)
... 47 more
2017-11-04 15:44:06,631 WARN (Slf4JLogger.java:151)- An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.lang.UnsupportedOperationException: unsupported frame content:
at com.xxx.ate.aplan.ms.netty.WebSocketFrameHandler.channelRead0(WebSocketFrameHandler.java:52)
at com.xxx.ate.aplan.ms.netty.WebSocketFrameHandler.channelRead0(WebSocketFrameHandler.java:1)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:192)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:651)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:574)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:488)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:450)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
at java.lang.Thread.run(Thread.java:745)

wenshao added a commit that referenced this issue Jul 17, 2019
xiongtj pushed a commit to fsxiaoke/fastjson that referenced this issue Aug 18, 2020
* branch/fs_1_1_65: (1273 commits)
  修改只有public属性可以反序列化
  当进行toJSONString的时候,默认如果重用对象的话,会使用引用的方式进行引用对象。
  提交fastjson兼容修改 case
  追加输出jar的命令
  修复只有默认构造异常
  优先走JSONCreator构造方法
  init
  add testcase.
  add more error info.
  bug fixed for JSONObject ordered.
  code format.
  add testcase for issue alibaba#1558
  add testcase.
  add testcase for issue alibaba#1543
  bug fixed for kotlin support. for issue alibaba#1524
  improved testcase for issue alibaba#1529
  bug fixed for 'is' prefix fieldName parser. for issue alibaba#1529
  1.1.65.android-SNAPSHOT
  1.1.64.android
  add hash collision test.
  ...

# Conflicts:
#	pom.xml
#	src/main/java/com/alibaba/fastjson/JSON.java
#	src/main/java/com/alibaba/fastjson/JSONObject.java
#	src/main/java/com/alibaba/fastjson/TypeReference.java
#	src/main/java/com/alibaba/fastjson/annotation/JSONType.java
#	src/main/java/com/alibaba/fastjson/parser/DefaultJSONParser.java
#	src/main/java/com/alibaba/fastjson/parser/EnumDeserializer.java
#	src/main/java/com/alibaba/fastjson/parser/Feature.java
#	src/main/java/com/alibaba/fastjson/parser/JSONLexer.java
#	src/main/java/com/alibaba/fastjson/parser/JavaBeanDeserializer.java
#	src/main/java/com/alibaba/fastjson/parser/JavaBeanInfo.java
#	src/main/java/com/alibaba/fastjson/parser/ListTypeFieldDeserializer.java
#	src/main/java/com/alibaba/fastjson/parser/MapDeserializer.java
#	src/main/java/com/alibaba/fastjson/parser/ParserConfig.java
#	src/main/java/com/alibaba/fastjson/parser/ThrowableDeserializer.java
#	src/main/java/com/alibaba/fastjson/parser/deserializer/FieldDeserializer.java
#	src/main/java/com/alibaba/fastjson/serializer/BigDecimalCodec.java
#	src/main/java/com/alibaba/fastjson/serializer/DateCodec.java
#	src/main/java/com/alibaba/fastjson/serializer/IntegerCodec.java
#	src/main/java/com/alibaba/fastjson/serializer/JavaBeanSerializer.java
#	src/main/java/com/alibaba/fastjson/serializer/MiscCodec.java
#	src/main/java/com/alibaba/fastjson/serializer/NumberCodec.java
#	src/main/java/com/alibaba/fastjson/util/FieldInfo.java
#	src/main/java/com/alibaba/fastjson/util/IdentityHashMap.java
#	src/main/java/com/alibaba/fastjson/util/TypeUtils.java
#	src/test/java/com/alibaba/json/bvt/JSONObjectTest_get_2.java
#	src/test/java/com/alibaba/json/bvt/MapRefTest1.java
#	src/test/java/com/alibaba/json/bvt/MapRefTest2.java
#	src/test/java/com/alibaba/json/bvt/MapRefTest3.java
#	src/test/java/com/alibaba/json/bvt/TestExternal3.java
#	src/test/java/com/alibaba/json/bvt/TestExternal4.java
#	src/test/java/com/alibaba/json/bvt/TestExternal5.java
#	src/test/java/com/alibaba/json/bvt/TestExternal6.java
#	src/test/java/com/alibaba/json/bvt/WriteClassNameTest.java
#	src/test/java/com/alibaba/json/bvt/WriteClassNameTest2.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_Exception.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_Johnny.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_NonStringKeyMap.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_SpitFire.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_SpitFire_3.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_SpitFire_4.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_SpitFire_5.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_SpitFire_6.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_cduym.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_dragoon26.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_dragoon26_1.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_dubbo.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_dubbo2.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_generic_1.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_184.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_291.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_415.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_430.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_462.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_lenolix_10.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_lenolix_5.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_lenolix_7.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_lenolix_8.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_lenolix_9.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_stv_liu.java
#	src/test/java/com/alibaba/json/bvt/bug/Bug_for_zhaoyao.java
#	src/test/java/com/alibaba/json/bvt/bug/CollectionEmptyMapTest.java
#	src/test/java/com/alibaba/json/bvt/bug/Issue146.java
#	src/test/java/com/alibaba/json/bvt/bug/SerDeserTest.java
#	src/test/java/com/alibaba/json/bvt/bug/TestJSONMap.java
#	src/test/java/com/alibaba/json/bvt/fullSer/EmtpyLinkedHashMapTest.java
#	src/test/java/com/alibaba/json/bvt/issue_1400/Issue1429.java
#	src/test/java/com/alibaba/json/bvt/issue_1500/Issue1503.java
#	src/test/java/com/alibaba/json/bvt/parser/EnumParserTest.java
#	src/test/java/com/alibaba/json/bvt/parser/TypeUtilsTest_castToJavaBean.java
#	src/test/java/com/alibaba/json/bvt/parser/deser/ConcurrentHashMapDeserializerTest.java
#	src/test/java/com/alibaba/json/bvt/parser/deser/DefaultObjectDeserializerTest3.java
#	src/test/java/com/alibaba/json/bvt/parser/deser/MapDeserializerTest.java
#	src/test/java/com/alibaba/json/bvt/parser/deser/ParseEmptyMap.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/MapTest.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest2.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_Collection.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_Collection2.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_List.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_List2.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_Set.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_Set2.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_Set3.java
#	src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_Set4.java
#	src/test/java/com/alibaba/json/test/benchmark/BenchmarkMain.java
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants