Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

fastjson1.1.46.sec01和1.2.41版本在key为integer等数字类型时不兼容 #1633

Closed
panmissl opened this issue Dec 6, 2017 · 2 comments
Milestone

Comments

@panmissl
Copy link

panmissl commented Dec 6, 2017

1.1.46.sec01,key为数字类型时会作toString处理。所以 parse出来的对象要用字符串类型为key才能获取。但在1.2.41版本,key还是会保持数字类型,所以parse出来的对象要用Integer类型才能取得。
下面是DefaultJSONParser.java的源码贴图:
1
2

下面是测试用例:

`public class FastjsonTest {

public static void main(String[] args) {
    String text = "{123:\"abc\"}";
    JSONObject obj = JSON.parseObject(text);
    int intKey = 123;
    String strKey = "123";

    String intValue = (String) obj.get(intKey);
    String strValue = (String) obj.get(strKey);

    System.out.println("intKey: " + intKey + ", intValue: " + intValue);
    System.out.println("strKey: " + strKey + ", strValue: " + strValue);
}

}`

@kimmking
Copy link
Contributor

kimmking commented Dec 6, 2017

有点奇怪,按理key必须是string

@wenshao
Copy link
Member

wenshao commented Dec 14, 2017

https://github.com/alibaba/fastjson/releases/tag/1.2.42
新版已发布,请使用新版本。

@wenshao wenshao closed this as completed Dec 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants