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

Java8 Instant反序列化失败, Unsupported Exception #3539

Closed
LeasyZhang opened this issue Nov 12, 2020 · 1 comment
Closed

Java8 Instant反序列化失败, Unsupported Exception #3539

LeasyZhang opened this issue Nov 12, 2020 · 1 comment

Comments

@LeasyZhang
Copy link

前端返回的Instant对象被序列化成
"date":{"nano":140000000,"epochSecond":1605106869}这种类型.
类的结构是
public class Bean {
Instant date;
//...
}
用JSONObject.parseObject(str, Bean.class);就会报错。
com.alibaba.fastjson.JSONException at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:693) at com.alibaba.fastjson.JSON.parseObject(JSON.java:395) at com.alibaba.fastjson.JSON.parseObject(JSON.java:299) at com.alibaba.fastjson.JSON.parseObject(JSON.java:572) at com.rc.testng.FastJsonTest.testPartial(FastJsonTest.java:26) 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 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:583) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.UnsupportedOperationException at com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec.deserialze(Jdk8DateCodec.java:235) at com.alibaba.fastjson.parser.deserializer.ContextObjectDeserializer.deserialze(ContextObjectDeserializer.java:9) at com.alibaba.fastjson.parser.deserializer.FastjsonASMDeserializer_1_DummyItem.deserialze(Unknown Source) at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:296) at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:688)

@oreoft
Copy link

oreoft commented Oct 29, 2021

这种类型的话,可以使用jackson反序列化,fastjson默认不能反序列化成这种,或者可以考虑自定义一个序列化器

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants