Remove the automatically display of getter in POJO

谁说我不能喝 提交于 2019-12-25 07:41:36

问题


Below I have given my POJO structure and the current out put and expected output. My requirement is, when I am printing the JSON format the variable called "applicationUsage " automatically included in my output JSON as key, But I dont want to add "applicationUsage " key in my json format and only wants to show the values stored in this field. Can anyone help me with the code.

    @JsonRootName(value = "MediationUserCacheRequest")
    @JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.NAME)
    @JsonTypeName(value = "MediationUserCacheRequest")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonPropertyOrder({ "eventName", "eventType", "action" })
    public class MedationUsageReport implements Serializable {
        private final static long serialVersionUID = -2077028266055844229L;
        @JsonProperty("eventName")
        private String eventName;
        @JsonProperty("eventType")
        private String eventType;
        @JsonProperty("action")
        private String action;
        private Map<String, List<MediationApplicationUsageResport>> applicationUsage = null;

        @JsonProperty("eventName")
        public String getEventName() {
            return eventName;
        }

        @JsonProperty("eventName")
        public void setEventName(String eventName) {
            this.eventName = eventName;
        }

        @JsonProperty("eventType")
        public String getEventType() {
            return eventType;
        }

        @JsonProperty("eventType")
        public void setEventType(String eventType) {
            this.eventType = eventType;
        }

        @JsonProperty("action")
        public String getAction() {
            return action;
        }

        @JsonProperty("action")
        public void setAction(String action) {
            this.action = action;
        }

        public Map<String, List<MediationApplicationUsageResport>> getApplicationUsage() {
            return applicationUsage;
        }

        public void setApplicationUsage(Map<String, List<MediationApplicationUsageResport>> applicationUsage) {
            this.applicationUsage = applicationUsage;
        }
    }

Output:

{"MediationUserCacheRequest":{"eventName":"STORAGE","eventType":"CURRENT_USAGE","action":"usagereport","applicationUsage":{"nuxeo":[ ...

Wanted:

{"MediationUserCacheRequest":{"eventName":"STORAGE","eventType":"CURRENT_USAGE","action":"usagereport",{"nuxeo":[ ...

回答1:


Simply mark it with @JsonAnyGetter annotation.

@JsonAnyGetter
public Map<String, List<MediationApplicationUsageResport>> getApplicationUsage() {
            return applicationUsage;
}



回答2:


Try annotating the getApplicationUsage() getter with @JsonUnwrapped



来源:https://stackoverflow.com/questions/41306886/remove-the-automatically-display-of-getter-in-pojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!