@Test public void testNormalize() { ObjectNode node = JsonNodeFactory.instance.objectNode(); node.put( "foo", "bar" ); Object o = JsonUtils.normalizeJsonTree( node ); assertEquals( java.util.LinkedHashMap.class, o.getClass() ); }
public static Object normalizeJsonTree( Object obj ) { if ( obj instanceof Map ) { @SuppressWarnings("unchecked") Map<Object, Object> m = ( Map<Object, Object> ) obj; Object o; UUID uuid; for ( Object k : m.keySet() ) { if ( k instanceof String && ( ( String ) k ).equalsIgnoreCase( "name" ) ) { continue; } o = m.get( k ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { m.put( k, uuid ); } else if ( o instanceof Integer ) { m.put( k, ( ( Integer ) o ).longValue() ); } else if ( o instanceof BigInteger ) { m.put( k, ( ( BigInteger ) o ).longValue() ); } } } else if ( obj instanceof List ) { @SuppressWarnings("unchecked") List<Object> l = ( List<Object> ) obj; Object o; UUID uuid; for ( int i = 0; i < l.size(); i++ ) { o = l.get( i ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { l.set( i, uuid ); } else if ( ( o instanceof Map ) || ( o instanceof List ) ) { normalizeJsonTree( o ); } else if ( o instanceof Integer ) { l.set( i, ( ( Integer ) o ).longValue() ); } else if ( o instanceof BigInteger ) { l.set( i, ( ( BigInteger ) o ).longValue() ); } } } else if ( obj instanceof String ) { UUID uuid = tryConvertToUUID( obj ); if ( uuid != null ) { return uuid; } } else if ( obj instanceof Integer ) { return ( ( Integer ) obj ).longValue(); } else if ( obj instanceof BigInteger ) { return ( ( BigInteger ) obj ).longValue(); } else if ( obj instanceof JsonNode ) { return mapper.convertValue( obj, Object.class ); } return obj; }
JsonUtils { public static Object normalizeJsonTree( Object obj ) { if ( obj instanceof Map ) { @SuppressWarnings("unchecked") Map<Object, Object> m = ( Map<Object, Object> ) obj; Object o; UUID uuid; for ( Object k : m.keySet() ) { if ( k instanceof String && ( ( String ) k ).equalsIgnoreCase( "name" ) ) { continue; } o = m.get( k ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { m.put( k, uuid ); } else if ( o instanceof Integer ) { m.put( k, ( ( Integer ) o ).longValue() ); } else if ( o instanceof BigInteger ) { m.put( k, ( ( BigInteger ) o ).longValue() ); } } } else if ( obj instanceof List ) { @SuppressWarnings("unchecked") List<Object> l = ( List<Object> ) obj; Object o; UUID uuid; for ( int i = 0; i < l.size(); i++ ) { o = l.get( i ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { l.set( i, uuid ); } else if ( ( o instanceof Map ) || ( o instanceof List ) ) { normalizeJsonTree( o ); } else if ( o instanceof Integer ) { l.set( i, ( ( Integer ) o ).longValue() ); } else if ( o instanceof BigInteger ) { l.set( i, ( ( BigInteger ) o ).longValue() ); } } } else if ( obj instanceof String ) { UUID uuid = tryConvertToUUID( obj ); if ( uuid != null ) { return uuid; } } else if ( obj instanceof Integer ) { return ( ( Integer ) obj ).longValue(); } else if ( obj instanceof BigInteger ) { return ( ( BigInteger ) obj ).longValue(); } else if ( obj instanceof JsonNode ) { return mapper.convertValue( obj, Object.class ); } return obj; } }
JsonUtils { public static Object normalizeJsonTree( Object obj ) { if ( obj instanceof Map ) { @SuppressWarnings("unchecked") Map<Object, Object> m = ( Map<Object, Object> ) obj; Object o; UUID uuid; for ( Object k : m.keySet() ) { if ( k instanceof String && ( ( String ) k ).equalsIgnoreCase( "name" ) ) { continue; } o = m.get( k ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { m.put( k, uuid ); } else if ( o instanceof Integer ) { m.put( k, ( ( Integer ) o ).longValue() ); } else if ( o instanceof BigInteger ) { m.put( k, ( ( BigInteger ) o ).longValue() ); } } } else if ( obj instanceof List ) { @SuppressWarnings("unchecked") List<Object> l = ( List<Object> ) obj; Object o; UUID uuid; for ( int i = 0; i < l.size(); i++ ) { o = l.get( i ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { l.set( i, uuid ); } else if ( ( o instanceof Map ) || ( o instanceof List ) ) { normalizeJsonTree( o ); } else if ( o instanceof Integer ) { l.set( i, ( ( Integer ) o ).longValue() ); } else if ( o instanceof BigInteger ) { l.set( i, ( ( BigInteger ) o ).longValue() ); } } } else if ( obj instanceof String ) { UUID uuid = tryConvertToUUID( obj ); if ( uuid != null ) { return uuid; } } else if ( obj instanceof Integer ) { return ( ( Integer ) obj ).longValue(); } else if ( obj instanceof BigInteger ) { return ( ( BigInteger ) obj ).longValue(); } else if ( obj instanceof JsonNode ) { return mapper.convertValue( obj, Object.class ); } return obj; }  }
JsonUtils { public static Object normalizeJsonTree( Object obj ) { if ( obj instanceof Map ) { @SuppressWarnings("unchecked") Map<Object, Object> m = ( Map<Object, Object> ) obj; Object o; UUID uuid; for ( Object k : m.keySet() ) { if ( k instanceof String && ( ( String ) k ).equalsIgnoreCase( "name" ) ) { continue; } o = m.get( k ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { m.put( k, uuid ); } else if ( o instanceof Integer ) { m.put( k, ( ( Integer ) o ).longValue() ); } else if ( o instanceof BigInteger ) { m.put( k, ( ( BigInteger ) o ).longValue() ); } } } else if ( obj instanceof List ) { @SuppressWarnings("unchecked") List<Object> l = ( List<Object> ) obj; Object o; UUID uuid; for ( int i = 0; i < l.size(); i++ ) { o = l.get( i ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { l.set( i, uuid ); } else if ( ( o instanceof Map ) || ( o instanceof List ) ) { normalizeJsonTree( o ); } else if ( o instanceof Integer ) { l.set( i, ( ( Integer ) o ).longValue() ); } else if ( o instanceof BigInteger ) { l.set( i, ( ( BigInteger ) o ).longValue() ); } } } else if ( obj instanceof String ) { UUID uuid = tryConvertToUUID( obj ); if ( uuid != null ) { return uuid; } } else if ( obj instanceof Integer ) { return ( ( Integer ) obj ).longValue(); } else if ( obj instanceof BigInteger ) { return ( ( BigInteger ) obj ).longValue(); } else if ( obj instanceof JsonNode ) { return mapper.convertValue( obj, Object.class ); } return obj; }  static String mapToJsonString( Object obj ); static String mapToFormattedJsonString( Object obj ); static Object parse( String json ); static String quoteString( String s ); static ByteBuffer toByteBuffer( Object obj ); static Object fromByteBuffer( ByteBuffer byteBuffer ); static Object fromByteBuffer( ByteBuffer byteBuffer, Class<?> clazz ); static JsonNode toJsonNode( Object obj ); @SuppressWarnings("unchecked") static Map<String, Object> toJsonMap( Object obj ); static Object normalizeJsonTree( Object obj ); static Object select( Object obj, String path ); static Object select( Object obj, String path, boolean buildResultTree ); static Object loadFromFilesystem( String filename ); }
JsonUtils { public static Object normalizeJsonTree( Object obj ) { if ( obj instanceof Map ) { @SuppressWarnings("unchecked") Map<Object, Object> m = ( Map<Object, Object> ) obj; Object o; UUID uuid; for ( Object k : m.keySet() ) { if ( k instanceof String && ( ( String ) k ).equalsIgnoreCase( "name" ) ) { continue; } o = m.get( k ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { m.put( k, uuid ); } else if ( o instanceof Integer ) { m.put( k, ( ( Integer ) o ).longValue() ); } else if ( o instanceof BigInteger ) { m.put( k, ( ( BigInteger ) o ).longValue() ); } } } else if ( obj instanceof List ) { @SuppressWarnings("unchecked") List<Object> l = ( List<Object> ) obj; Object o; UUID uuid; for ( int i = 0; i < l.size(); i++ ) { o = l.get( i ); uuid = tryConvertToUUID( o ); if ( uuid != null ) { l.set( i, uuid ); } else if ( ( o instanceof Map ) || ( o instanceof List ) ) { normalizeJsonTree( o ); } else if ( o instanceof Integer ) { l.set( i, ( ( Integer ) o ).longValue() ); } else if ( o instanceof BigInteger ) { l.set( i, ( ( BigInteger ) o ).longValue() ); } } } else if ( obj instanceof String ) { UUID uuid = tryConvertToUUID( obj ); if ( uuid != null ) { return uuid; } } else if ( obj instanceof Integer ) { return ( ( Integer ) obj ).longValue(); } else if ( obj instanceof BigInteger ) { return ( ( BigInteger ) obj ).longValue(); } else if ( obj instanceof JsonNode ) { return mapper.convertValue( obj, Object.class ); } return obj; }  static String mapToJsonString( Object obj ); static String mapToFormattedJsonString( Object obj ); static Object parse( String json ); static String quoteString( String s ); static ByteBuffer toByteBuffer( Object obj ); static Object fromByteBuffer( ByteBuffer byteBuffer ); static Object fromByteBuffer( ByteBuffer byteBuffer, Class<?> clazz ); static JsonNode toJsonNode( Object obj ); @SuppressWarnings("unchecked") static Map<String, Object> toJsonMap( Object obj ); static Object normalizeJsonTree( Object obj ); static Object select( Object obj, String path ); static Object select( Object obj, String path, boolean buildResultTree ); static Object loadFromFilesystem( String filename );  }