JsonUtil { private static Map<String, byte[]> toXAttrMap(final List<?> objects) throws IOException { if (objects == null) { return null; } else if (objects.isEmpty()) { return Maps.newHashMap(); } else { final Map<String, byte[]> xAttrs = Maps.newHashMap(); for (Object object : objects) { Map<?, ?> m = (Map<?, ?>) object; String name = (String) m.get("name"); String value = (String) m.get("value"); xAttrs.put(name, decodeXAttrValue(value)); } return xAttrs; } }  static String toJsonString(
      final Token<? extends TokenIdentifier> token); static String toJsonString(final Exception e); static String toJsonString(final String key, final Object value); static String toJsonString(final HdfsFileStatus status,
      boolean includeType); static String toJsonString(final LocatedBlocks locatedblocks
      ); static String toJsonString(final ContentSummary contentsummary); static String toJsonString(final MD5MD5CRC32FileChecksum checksum); static String toJsonString(final AclStatus status); static String toJsonString(final List<XAttr> xAttrs); static String toJsonString(final List<XAttr> xAttrs,
      final XAttrCodec encoding); static byte[] getXAttr(final Map<?, ?> json, final String name); static Map<String, byte[]> toXAttrs(final Map<?, ?> json); static List<String> toXAttrNames(final Map<?, ?> json);  }
@Test public void testToXAttrMap() throws IOException { String jsonString = "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," + "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}"; ObjectReader reader = new ObjectMapper().reader(Map.class); Map<?, ?> json = reader.readValue(jsonString); XAttr xAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a1").setValue(XAttrCodec.decodeValue("0x313233")).build(); XAttr xAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a2").setValue(XAttrCodec.decodeValue("0x313131")).build(); List<XAttr> xAttrs = Lists.newArrayList(); xAttrs.add(xAttr1); xAttrs.add(xAttr2); Map<String, byte[]> xAttrMap = XAttrHelper.buildXAttrMap(xAttrs); Map<String, byte[]> parsedXAttrMap = JsonUtil.toXAttrs(json); Assert.assertEquals(xAttrMap.size(), parsedXAttrMap.size()); Iterator<Entry<String, byte[]>> iter = xAttrMap.entrySet().iterator(); while(iter.hasNext()) { Entry<String, byte[]> entry = iter.next(); Assert.assertArrayEquals(entry.getValue(), parsedXAttrMap.get(entry.getKey())); } }