Solve com.alibaba.fastjson.JSONException: autoType is not support exception handling

Reprinted from: https://blog.csdn.net/wgzhl2008/article/details/82184240

Narrative

Recently when using spring-data-redis, the use of serialization fastjson

GenericFastJsonRedisSerializer

Sequence of normal, but the following exception occurs during deserialization

com.alibaba.fastjson.JSONException: autoType is not support. com.hongshu.groovy.dto.Account

Read the fastjson.ParserConfig source code, I found in the 1078 line abnormality occurs

Because GenericFastJsonRedisSerializer , as shown below, the autoTypeSupport set to true,

Resulting in generation of abnormal reason is because when the fastjson deserialization, build JavaBeanInfo. Whether there is a default constructor was examined. After seeing reason, directly to your Domain to go see, it really is not the default method of construction.

Summary: When using fastjson class serialization, especially in support of redis this sequence, in the class to be added to ensure that a default constructor, or during deserialization, fastjosn deserialized according to typeName, the exception occurs .

Published 27 original articles · won praise 32 · Views 100,000 +

Guess you like

Origin blog.csdn.net/lizhengyu891231/article/details/104675134