fastjson 1.2.62 反序列化org.springframework.data.geo.Point报错

tjjdgumg  于 2021-11-27  发布在  Java
关注(0)|答案(3)|浏览(325)

添加
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
或者
ParserConfig.getGlobalInstance().addAccept("org.springframework.data.geo.Point");
均无效

l2osamch

l2osamch1#

把你的json发出来

lb3vh1jj

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}
qvsjd97n

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()
        );
    }

相关问题