4
添加 ParserConfig.getGlobalInstance().setAutoTypeSupport(true); 或者 ParserConfig.getGlobalInstance().addAccept("org.springframework.data.geo.Point"); 均无效
添加 ParserConfig.getGlobalInstance().setAutoTypeSupport(true); 或者 ParserConfig.getGlobalInstance().addAccept("org.springframework.data.geo.Point"); 均无效
把你的json发出来
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}
发现这样也会报同样的错(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()
);
}