Use class name as root key for JSON Jackson serialization

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

    To achieve this you need to use the JsonTypeInfo annotation on your class and in particular WRAPPER_OBJECT

    @JsonTypeName("foo")                                                                                         
    @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT ,use = JsonTypeInfo.Id.NAME)
    
    public class Bar(){
    )
    

提交回复
热议问题