Force Jackson to add addional wrapping using annotations

前端 未结 7 1176
渐次进展
渐次进展 2021-02-12 20:41

I have the following class:

public class Message {
    private String text;

    public String getText() {
        return text;
    }

    public void setText(St         


        
7条回答
  •  没有蜡笔的小新
    2021-02-12 21:33

    Provided you don't mind the json having a capital m in message, then the simplest way to do this is to annotate your class with @JsonTypeInfo.

    You would add:

    @JsonTypeInfo(include=As.WRAPPER_OBJECT, use=Id.NAME)
    public class Message {
      // ...
    }
    

    to get {"Message":{"text":"Text"}}

提交回复
热议问题