Force Jackson to add addional wrapping using annotations

前端 未结 7 1026
渐次进展
渐次进展 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:36

    If using spring, then in application.properties file add following:-

    spring.jackson.serialization.WRAP_ROOT_VALUE=true

    And then use @JsonRootName annotation on any of your class that you wish to serialize. e.g.

    @JsonRootName("user")
    public class User {
        private String name;
        private Integer age;
    }
    

提交回复
热议问题