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

error with no blank between : and [ #504

Closed
yuanmomo opened this issue Feb 23, 2016 · 3 comments
Closed

error with no blank between : and [ #504

yuanmomo opened this issue Feb 23, 2016 · 3 comments

Comments

@yuanmomo
Copy link

please run the code as follows:

the only difference between userStr1 and userStr2 is there is a blank betweent ':' and '[' after "models".

`
public class FastJsonTest {
public static void main(String[] args) {
String userStr1 = "{"id":"qfHdV0ez0N10", "ext":{"models": ["10000","10002"] } }";
String userStr2 = "{"id":"qfHdV0ez0N10", "ext":{"models":["10000","10002"] } }";
User user = JSON.parseObject(userStr1, User.class);
System.out.println(user);
user = JSON.parseObject(userStr2, User.class);
System.out.println(user);
}

public static class User {
    private String id;
    private UserExt ext;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public UserExt getExt() {
        return ext;
    }

    public void setExt(UserExt ext) {
        this.ext = ext;
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", ext=" + ext +
                '}';
    }
}

public static class UserExt {
    private List<String> models;

    public List<String> getModels() {
        return models;
    }

    public void setModels(List<String> models) {
        this.models = models;
    }

    @Override
    public String toString() {
        return "UserExt{" +
                "models=" + models +
                '}';
    }
}

}`

you will get the result:
User{id='qfHdV0ez0N10', ext=UserExt{models=[10000, 10002]}}
Exception in thread "main" com.alibaba.fastjson.JSONException: unclosed.str
at com.alibaba.fastjson.parser.JSONLexerBase.scanSymbol(JSONLexerBase.java:678)
at com.alibaba.fastjson.parser.JSONLexerBase.scanSymbol(JSONLexerBase.java:624)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:241)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseRest(ASMJavaBeanDeserializer.java:100)
at Fastjson_ASM_UserExt_3.deserialze(Unknown Source)
at com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer.parseField(DefaultFieldDeserializer.java:33)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseField(ASMJavaBeanDeserializer.java:74)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer$InnerJavaBeanDeserializer.parseField(ASMJavaBeanDeserializer.java:86)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:330)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseRest(ASMJavaBeanDeserializer.java:100)
at Fastjson_ASM_User_1.deserialze(Unknown Source)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:551)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:251)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:227)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:186)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:304)
at com.foxdsp.adserver.test.FastJsonTest.main(FastJsonTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Process finished with exit code 1
_

the userStr1 is deserialize successfully. but userStr2 not.
0cb4d314-9639-4186-91d7-c8254e98a422

Please check this , thx.

@yuanmomo
Copy link
Author

fastjson version is 1.2.7

» java -version
java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)

@wenshao
Copy link
Member

wenshao commented Feb 28, 2016

bug fixed.
87151e7

@wenshao wenshao closed this as completed Feb 28, 2016
@yuanmomo
Copy link
Author

@wenshao Thanks,really appreciate this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants