fastjson The version for Java differs from that for Android

vnjpjtjt  于 2021-11-27  发布在  Java
关注(0)|答案(0)|浏览(233)

There is a period of JSON as follows:

{
    "code": 200,
    "data": {
        "access_token": "Bqg3RtW6hUefRODN46duX2oJCXgKowy_",
        "user_id": 448911
    },
    "message": "OK",
    "success": true
}

There are two JavaBeans as follows:

public class Token {

    @JSONField(name = "access_token")
    private String token;

    @JSONField(name = "user_id")
    private String userId;

    public Token() {
    }

    ...
}
public class TokenWrapper {

    @JSONField(name = "data")
    private Token mToken;

    @JSONField(name = "message")
    private String message;

    @JSONField(name = "code")
    private int code;

    @JSONField(name = "success")
    private boolean success;

    public TokenWrapper() {
    }

    ...
}

In JavaEE development, use the Java version: com.alibaba:fastjson:1.2.44, parse the code as follows:

TokenWrapper wrapper = JSON.parseObject(loginJson, TokenWrapper.class);

Android development or JavaEE development, the use of the Android version: com.alibaba:fastjson:1.1.67.android, the analysis code is as follows:

TokenWrapper wrapper = JSON.parseObject(loginJson, TokenWrapper.class);

As a result of the analysis, When using the Java version, mToken object in the wrapper is actually empty, and use the Android version, the results of the analysis as I wish.

Is this a bug for the Java version? Can anyone provide a solution for me if not?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题