0

下面我给出了我的 POJO 结构以及当前输出和预期输出。我的要求是,当我打印 JSON 格式时,名为“applicationUsage”的变量会自动包含在我的输出 JSON 中作为键,但我不想在我的 json 格式中添加“applicationUsage”键,只想显示存储在此中的值场地。谁能帮我写代码。

    @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;
        }
    }

输出:

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

通缉:

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

2 回答 2

1

只需使用 @JsonAnyGetter 注释标记它。

@JsonAnyGetter
public Map<String, List<MediationApplicationUsageResport>> getApplicationUsage() {
            return applicationUsage;
}
于 2016-12-24T19:36:04.220 回答
0

尝试使用@JsonUnwrapped注释getApplicationUsage()getter

于 2016-12-23T20:38:00.037 回答