下面我给出了我的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":[ ...
答案 0 :(得分:1)
只需使用@JsonAnyGetter注释标记它。
@JsonAnyGetter
public Map<String, List<MediationApplicationUsageResport>> getApplicationUsage() {
return applicationUsage;
}
答案 1 :(得分:0)
尝试使用@JsonUnwrapped
注释Layoutmanager
getter