去除POJO中getter的自动显示

Remove the automatically display of getter in POJO

下面我给出了我的 POJO 结构以及当前输出和预期输出。我的要求是,当我打印 JSON 格式时,名为 "applicationUsage " 的变量自动包含在我的输出中 JSON 作为键,但我不想在我的文件中添加 "applicationUsage " 键json 格式,只想显示存储在此字段中的值。任何人都可以帮助我的代码。

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

尝试用 @JsonUnwrapped

注释 getApplicationUsage() getter

简单的用@JsonAnyGetter注解标注即可

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