Exemplo n.º 1
0
 // 将Json集合转换为大Json
 public static XContentBuilder parse(List<Json> list, String arrayName) throws IOException {
   XContentBuilder builder = XContentFactory.jsonBuilder();
   builder.startObject();
   if (list == null || list.size() == 0) {
     builder.field("total", 0);
     builder.startArray(arrayName);
   } else {
     builder.field("total", list.size());
     builder.startArray(arrayName);
     for (Json json : list) {
       builder.startObject();
       Iterator<Entry<String, Object>> it = json.entrySet().iterator();
       while (it.hasNext()) {
         Entry<String, Object> entry = it.next();
         builder.field(entry.getKey()).value(entry.getValue());
       }
       builder.endObject();
     }
   }
   builder.endArray();
   builder.endObject();
   return builder;
 }
Exemplo n.º 2
0
 public static Json parse(Map map) {
   ObjectMapper objectMapper = new ObjectMapper();
   Json json = new Json();
   json.putAll(map);
   return json;
 }