简体   繁体   中英

How do I configure a Jackson ObjectMapper to show the root value?

In my Spring project i was added jackson 1 and now it is 2 then i have seen this difference. Previously response was cumming right with 'loginResponse' now no object name in Json .
Old object class for loginResponse as follows :

public class LoginResponse {

    private String code;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

}

我相信应该将SerializationFeature.WRAP_ROOT_VALUE设置为true,而不是像上述片段中的ur那样设置为false。

You set it to false instead of true.

Use this.

ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM