添加ParserConfig.getGlobalInstance().setAutoTypeSupport(true);或者ParserConfig.getGlobalInstance().addAccept("org.springframework.data.geo.Point");均无效
l2osamch1#
把你的json发出来
lb3vh1jj2#
code:
public static void main(String[] args) { ParserConfig.getGlobalInstance().addAccept("org.springframework.data.geo.Point"); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteClassName); JSON.parseObject( "{\"@type\":\"org.springframework.data.geo.Point\",\"x\":1.2,\"y\":0.3}".getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8, Object.class, fastJsonConfig.getParserConfig(), fastJsonConfig.getParseProcess(), JSON.DEFAULT_PARSER_FEATURE, fastJsonConfig.getFeatures() ); }
json:
{"@type":"org.springframework.data.geo.Point","x":1.2,"y":0.3}
qvsjd97n3#
发现这样也会报同样的错(FastJsonRedisSerializer里copy的)
public static void main(String[] args) { ParserConfig.getGlobalInstance().addAccept("org.springframework.data.geo.Point"); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteClassName); byte[] bytes = JSON.toJSONBytes( fastJsonConfig.getCharset(), new Point(1.2, 0.3), fastJsonConfig.getSerializeConfig(), fastJsonConfig.getSerializeFilters(), fastJsonConfig.getDateFormat(), JSON.DEFAULT_GENERATE_FEATURE, fastJsonConfig.getSerializerFeatures() ); JSON.parseObject( bytes, fastJsonConfig.getCharset(), Object.class, fastJsonConfig.getParserConfig(), fastJsonConfig.getParseProcess(), JSON.DEFAULT_PARSER_FEATURE, fastJsonConfig.getFeatures() ); }
3条答案
按热度按时间l2osamch1#
把你的json发出来
lb3vh1jj2#
code:
json:
qvsjd97n3#
发现这样也会报同样的错(FastJsonRedisSerializer里copy的)