public static Object normalizeJsonTree()

in stack/core/src/main/java/org/apache/usergrid/utils/JsonUtils.java [195:255]


    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;
    }