Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants