Use class name as root key for JSON Jackson serialization

前端 未结 11 2780
长情又很酷
长情又很酷 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

    There is also a nice annotation for this:

    @JsonRootName(value = "my_pojo")
    public class MyPojo{
      ...
    }
    

    will generate:

    {
      "my_pojo" : {...}
    }
    

提交回复
热议问题