是,使用一個包裝對象具有嵌入的地圖,作爲@digitialjoel建議。這是一個具體的例子:
class DocInfo {
private Map<String, Object> docInfo;
public DocInfo() {
super();
}
public DocInfo(final Map<String, Object> docInfo) {
super();
this.docInfo = docInfo;
}
// Getters, setters
}
final Map<String, Object> data = new LinkedHashMap<String, Object>(4);
data.put("field1", "value1");
data.put("field2", "value2");
data.put("field3", "value3");
data.put("field4", "value4");
final DocInfo info = new DocInfo(data);
final ObjectMapper mapper = new ObjectMapper();
final String json = mapper.writeValueAsString(info);
System.out.println(json);
輸出:
{ 「DOCINFO」:{ 「字段1」: 「VALUE1」, 「FIELD2」: 「VALUE2」, 「字段3」: 「值3」 「字段4」: 「VALUE4」}}
是,地圖是要走的路。 Upvoted。 – Perception 2013-04-10 22:29:17
那工作...謝謝:) – AnujKu 2013-04-10 22:53:15