Remove the automatically display of getter in POJO

743 views Asked by At

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":[ ...
2

There are 2 answers

0
Souvik On BEST ANSWER

Simply mark it with @JsonAnyGetter annotation.

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

Try annotating the getApplicationUsage() getter with @JsonUnwrapped