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<String, Object>(); 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 Map<String, Object> getEcPolicyAsMap(
      final ErasureCodingPolicy ecPolicy); static String toJsonString(final DirectoryListing listing); static String toJsonString(final LocatedBlocks locatedblocks
      ); static String toJsonString(final ContentSummary contentsummary); static String toJsonString(final QuotaUsage quotaUsage); static String toJsonString(final MD5MD5CRC32FileChecksum checksum); static String toJsonString(final AclStatus status); static String toJsonString(final List<XAttr> xAttrs, 
      final XAttrCodec encoding); static String toJsonString(final List<XAttr> xAttrs); static String toJsonString(Object obj); static String toJsonString(BlockStoragePolicy[] storagePolicies); static String toJsonString(BlockStoragePolicy storagePolicy); static String toJsonString(FsServerDefaults serverDefaults); static String toJsonString(SnapshotDiffReport diffReport); static String toJsonString(
      SnapshottableDirectoryStatus[] snapshottableDirectoryList); static String toJsonString(SnapshotStatus[] snapshotList); static String toJsonString(BlockLocation[] locations);  }
@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, r.get("name")); Assert.assertEquals("127.0.0.1", 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); }