Example #1
0
 public static String toJsonString(final List<XAttr> xAttrs) throws IOException {
   final List<String> names = Lists.newArrayListWithCapacity(xAttrs.size());
   for (XAttr xAttr : xAttrs) {
     names.add(XAttrHelper.getPrefixName(xAttr));
   }
   String ret = JSON.toString(names);
   final Map<String, Object> finalMap = new TreeMap<String, Object>();
   finalMap.put("XAttrNames", ret);
   return JSON.toString(finalMap);
 }
Example #2
0
  private static Map<String, Object> toJsonMap(final XAttr xAttr, final XAttrCodec encoding)
      throws IOException {
    if (xAttr == null) {
      return null;
    }

    final Map<String, Object> m = new TreeMap<String, Object>();
    m.put("name", XAttrHelper.getPrefixName(xAttr));
    m.put(
        "value",
        xAttr.getValue() != null ? XAttrCodec.encodeValue(xAttr.getValue(), encoding) : null);
    return m;
  }