fastjson icon indicating copy to clipboard operation
fastjson copied to clipboard

老问题,field的key(@type)的顺序必须在第一位,否则序列化反序列化没有数据

Open qiuker521 opened this issue 7 years ago • 4 comments

#406 #291 #1941

但是这几个都被关闭了。

wenshao commented on 13 Apr 2016
bug fixed. included in 1.2.9 & 1.1.49.android

一个可执行的代码如下:

public class App {
    private static String s1 = "{\"a\":\"b\",\"@type\":\"java.util.HashMap\"}";
    private static String s2 = "{\"@type\":\"java.util.HashMap\",\"a\":\"b\"}";

    public static void main(String[] args) {
        s1();
        s2();
    }

    public static void s1() {
        System.out.println(JSON.toJSONString(JSON.parse(s1)));
    }

    public static void s2() {
        System.out.println(JSON.toJSONString(JSON.parse(s2)));
    }
}

期待结果是

{"a":"b"}
{"a":"b"}

实际结果是

{}
{"a":"b"}

版本:1.2.58,maven目前的最新版。

qiuker521 avatar May 18 '19 07:05 qiuker521

+1

perdonare avatar Jun 14 '19 09:06 perdonare

这个问题在最新版本的1.2.67依然存在

MasonPD avatar Mar 22 '20 03:03 MasonPD

1.2.75版本依然存在

Dave0904 avatar Dec 15 '20 15:12 Dave0904

1.2.73同样存在着

Harson-Zhang avatar Jan 16 '21 05:01 Harson-Zhang