JsonUtil { private static Map<String, Object> toJsonMap( final Token<? extends TokenIdentifier> token) throws IOException { if (token == null) { return null; } final Map<String, Object> m = new TreeMap<>(); m.put("urlString", token.encodeToUrlString()); return m; }  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 testToDatanodeInfoWithName() throws Exception { Map<String, Object> response = new HashMap<String, Object>(); String name = "127.0.0.1:1004"; response.put("name", name); response.put("hostName", "localhost"); response.put("storageID", "fake-id"); response.put("infoPort", 1338l); response.put("ipcPort", 1339l); response.put("capacity", 1024l); response.put("dfsUsed", 512l); response.put("remaining", 512l); response.put("blockPoolUsed", 512l); response.put("lastUpdate", 0l); response.put("xceiverCount", 4096l); response.put("networkLocation", "foo.bar.baz"); response.put("adminState", "NORMAL"); response.put("cacheCapacity", 123l); response.put("cacheUsed", 321l); DatanodeInfo di = JsonUtilClient.toDatanodeInfo(response); Assert.assertEquals(name, di.getXferAddr()); Map<String, Object> r = JsonUtil.toJsonMap(di); Assert.assertEquals(name, (String)r.get("name")); Assert.assertEquals("127.0.0.1", (String)r.get("ipAddr")); Assert.assertEquals(1004, (int)(Integer)r.get("xferPort")); String[] badNames = {"127.0.0.1", "127.0.0.1:", ":", "127.0.0.1:sweet", ":123"}; for (String badName : badNames) { response.put("name", badName); checkDecodeFailure(response); } response.remove("name"); checkDecodeFailure(response); response.put("ipAddr", "127.0.0.1"); checkDecodeFailure(response); }