Use class name as root key for JSON Jackson serialization

前端 未结 11 2796
长情又很酷
长情又很酷 2020-11-27 18:05

Suppose I have a pojo:

import org.codehaus.jackson.map.*;

public class MyPojo {
    int id;
    public int getId()
    { return this.id; }

    public void          


        
11条回答
  •  自闭症患者
    2020-11-27 18:30

    @JsonTypeInfo(include=As.WRAPPER_OBJECT, use=Id.NAME) 
    

    This annotation works perfectly, as suggested by Arun Prakash. I was trying to get json in this form:

    {"Rowset":{"ROW":{"receiptno":"881604199388936","status":"SUCCESS"}}}
    

    but getting like this:

    {"ROW":{"receiptno":"881604199388936","status":"SUCCESS"}}
    

    Now that annotation resolved my problem.

提交回复
热议问题