usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [26/52] [abbrv] git commit: More JSON serialization fixes: EntityRef and CredentialsInfo should not be serialized with type info.
Date Wed, 03 Sep 2014 22:11:21 GMT
More JSON serialization fixes: EntityRef and CredentialsInfo should not be serialized with
type info.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/dc12e8b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/dc12e8b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/dc12e8b6

Branch: refs/heads/two-dot-o-push-notifications
Commit: dc12e8b60bad2709fc53c63ab7d92eed158a0144
Parents: b09b154
Author: Dave Johnson <dmjohnson@apigee.com>
Authored: Fri Aug 29 13:47:13 2014 -0400
Committer: Dave Johnson <dmjohnson@apigee.com>
Committed: Fri Aug 29 13:47:13 2014 -0400

----------------------------------------------------------------------
 .../usergrid/persistence/CredentialsInfo.java   |  13 +-
 .../apache/usergrid/persistence/EntityRef.java  |   4 -
 .../persistence/GeoQueryBooleanTest.java        |  64 ++--
 .../common/src/test/resources/log4j.properties  |  29 ++
 .../persistence/model/field/AbstractField.java  |   2 +-
 .../usergrid/persistence/model/field/Field.java |   2 +-
 .../model/src/test/resources/log4j.properties   |  29 ++
 .../usergrid/persistence/index/query/Query.java |  15 +-
 .../persistence/index/utils/JsonUtils.java      | 329 -------------------
 9 files changed, 120 insertions(+), 367 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc12e8b6/stack/core/src/main/java/org/apache/usergrid/persistence/CredentialsInfo.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/CredentialsInfo.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/CredentialsInfo.java
index edfffcf..957f8a8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/CredentialsInfo.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/CredentialsInfo.java
@@ -17,23 +17,16 @@
 package org.apache.usergrid.persistence;
 
 
+import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.fasterxml.jackson.annotation.JsonAnySetter;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import java.io.Serializable;
 import java.util.Map;
 import java.util.TreeMap;
-
 import javax.xml.bind.annotation.XmlRootElement;
 
-//import org.codehaus.jackson.annotate.JsonAnyGetter;
-//import org.codehaus.jackson.annotate.JsonAnySetter;
-//import org.codehaus.jackson.annotate.JsonTypeInfo;
-//import org.codehaus.jackson.map.annotate.JsonSerialize;
-//import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-import com.fasterxml.jackson.annotation.*;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-
 
 @XmlRootElement
-@JsonTypeInfo( use= JsonTypeInfo.Id.CLASS,include= JsonTypeInfo.As.WRAPPER_OBJECT,property="@class"
)
 public class CredentialsInfo implements Comparable<CredentialsInfo>,Serializable {
 
     boolean recoverable;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc12e8b6/stack/core/src/main/java/org/apache/usergrid/persistence/EntityRef.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityRef.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityRef.java
index 8133840..56c75cc 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityRef.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityRef.java
@@ -16,12 +16,8 @@
  */
 package org.apache.usergrid.persistence;
 
-
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-
 import java.util.UUID;
 
-@JsonTypeInfo( use= JsonTypeInfo.Id.CLASS,include= JsonTypeInfo.As.WRAPPER_OBJECT,property="@class"
)
 public interface EntityRef {
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc12e8b6/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryBooleanTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryBooleanTest.java
b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryBooleanTest.java
index 8ba860a..0d9810f 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryBooleanTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryBooleanTest.java
@@ -123,6 +123,8 @@ public class GeoQueryBooleanTest extends AbstractCoreIT {
         EntityManager em = setup.getEmf().getEntityManager( applicationId );
         assertNotNull( em );
 
+        // define two users at a location 
+
         Map<String, Object> properties = new LinkedHashMap<String, Object>()
{{
             put( "username", "bart" );
             put( "email", "bart@example.com" );
@@ -132,6 +134,7 @@ public class GeoQueryBooleanTest extends AbstractCoreIT {
                 add( new LinkedHashMap<String, Object>() {{ put("name", "mina"); }});
             }});            
             put( "blockedBy", new ArrayList<Object>() {{
+                add( new LinkedHashMap<String, Object>() {{ put("name", "gertrude");
}});
                 add( new LinkedHashMap<String, Object>() {{ put("name", "isabell");
}});
             }});
             put( "location", new LinkedHashMap<String, Object>() {{
@@ -142,25 +145,46 @@ public class GeoQueryBooleanTest extends AbstractCoreIT {
 
         Entity userBart = em.create( "user", properties );
         assertNotNull( userBart );
-//
-//        properties = new LinkedHashMap<String, Object>() {{
-//            put( "username", "fred" );
-//            put( "email", "fred@example.com" );
-//            put( "block", new ArrayList<Object>() {{
-//                add( new LinkedHashMap<String, Object>() {{ put("name", "steve");
}});
-//                add( new LinkedHashMap<String, Object>() {{ put("name", "mina");
}});
-//            }});
-//            put( "blockedBy", new ArrayList<Object>() {{
-//                add( new LinkedHashMap<String, Object>() {{ put("name", "bart");
}});
-//            }});
-//            put( "location", new LinkedHashMap<String, Object>() {{
-//                put("latitude", 37.776753 );
-//                put("longitude", -122.407846 );
-//            }} ); 
-//        }};
-//
-//        Entity userFred = em.create( "user", properties );
-//        assertNotNull( userFred );
-    }
+
+        properties = new LinkedHashMap<String, Object>() {{
+            put( "username", "fred" );
+            put( "email", "fred@example.com" );
+            put( "block", new ArrayList<Object>() {{
+                add( new LinkedHashMap<String, Object>() {{ put("name", "steve"); }});
+                add( new LinkedHashMap<String, Object>() {{ put("name", "mina"); }});
+            }});
+            put( "blockedBy", new ArrayList<Object>() {{
+                add( new LinkedHashMap<String, Object>() {{ put("name", "bart"); }});
+                add( new LinkedHashMap<String, Object>() {{ put("name", "beth"); }});
+            }});
+            put( "location", new LinkedHashMap<String, Object>() {{
+                put("latitude", 37.776753 );
+                put("longitude", -122.407846 );
+            }} ); 
+        }};
+
+        Entity userFred = em.create( "user", properties );
+        assertNotNull( userFred );
+
+        em.refreshIndex();
+
+        // define center point about 300m from that location
+        Point center = new Point( 37.774277, -122.404744 );
+
+        // one user within 400 meters IS NOT blocked by bart
+        Query query = Query.fromQL( 
+            "select * where NOT blockedBy.name='bart' and location within 400 of " 
+               + center.getLat() + "," + center.getLon());
+        Results listResults = em.searchCollection( em.getApplicationRef(), "users", query
);
+        assertEquals( 2, listResults.size() );
+
+        // one user within 400 meters IS blocked by bart
+        query = Query.fromQL( 
+            "select * where blockedBy.name='bart' and location within 400 of " 
+               + center.getLat() + "," + center.getLon());
+        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+        assertEquals( 2, listResults.size() );
+
+     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc12e8b6/stack/corepersistence/common/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/resources/log4j.properties b/stack/corepersistence/common/src/test/resources/log4j.properties
new file mode 100644
index 0000000..6f6d1be
--- /dev/null
+++ b/stack/corepersistence/common/src/test/resources/log4j.properties
@@ -0,0 +1,29 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# for production, you should probably set the root to INFO
+# and the pattern to %c instead of %l.  (%l is slower.)
+
+# output messages into a rolling log file as well as stdout
+log4j.rootLogger=INFO,stdout
+
+# stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+#log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) %c{1} - %m%n
+
+log4j.logger.org.apache.usergrid=INFO

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc12e8b6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
index 17af18c..0283277 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
@@ -25,7 +25,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
 /**
  * Base class for data information
  */
-@JsonTypeInfo( use= JsonTypeInfo.Id.CLASS,include= JsonTypeInfo.As.WRAPPER_OBJECT,property="@class"
)
+@JsonTypeInfo( use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class"
)
 public abstract class AbstractField<T> implements Field<T> {
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc12e8b6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
index 8419b6b..9da0d4e 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
@@ -29,7 +29,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
  * (in the java runtime) The V is the value of the field
  * @param <T>
  */
-@JsonTypeInfo( use= JsonTypeInfo.Id.CLASS,include= JsonTypeInfo.As.WRAPPER_OBJECT,property="@class"
)
+@JsonTypeInfo( use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class"
)
 public interface Field<T> extends Serializable {
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc12e8b6/stack/corepersistence/model/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/test/resources/log4j.properties b/stack/corepersistence/model/src/test/resources/log4j.properties
new file mode 100644
index 0000000..6f6d1be
--- /dev/null
+++ b/stack/corepersistence/model/src/test/resources/log4j.properties
@@ -0,0 +1,29 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# for production, you should probably set the root to INFO
+# and the pattern to %c instead of %l.  (%l is slower.)
+
+# output messages into a rolling log file as well as stdout
+log4j.rootLogger=INFO,stdout
+
+# stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+#log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) %c{1} - %m%n
+
+log4j.logger.org.apache.usergrid=INFO

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc12e8b6/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
index 569c08d..f845e63 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
@@ -30,6 +30,8 @@ import java.util.Set;
 import java.util.UUID;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
 import org.antlr.runtime.ANTLRStringStream;
 import org.antlr.runtime.ClassicToken;
 import org.antlr.runtime.CommonTokenStream;
@@ -55,7 +57,6 @@ import org.apache.usergrid.persistence.index.query.tree.Operand;
 import org.apache.usergrid.persistence.index.query.tree.QueryVisitor;
 import org.apache.usergrid.persistence.index.utils.ClassUtils;
 import org.apache.usergrid.persistence.index.utils.ConversionUtils;
-import org.apache.usergrid.persistence.index.utils.JsonUtils;
 import org.apache.usergrid.persistence.index.utils.ListUtils;
 import org.apache.usergrid.persistence.index.utils.MapUtils;
 import org.elasticsearch.index.query.FilterBuilder;
@@ -102,6 +103,9 @@ public class Query {
     private String collection;
     private String ql;
 
+    private static ObjectMapper mapper = new ObjectMapper();
+
+
     List<Operand> filterClauses = new ArrayList<Operand>();
 
     public Query() {
@@ -232,7 +236,14 @@ public class Query {
 
 
     public static Query fromJsonString( String json ) throws QueryParseException {
-        Object o = JsonUtils.parse( json );
+
+        Object o;
+        try {
+            o = mapper.readValue( json, Object.class );
+        } catch (IOException ex) {
+            throw new QueryParseException("Error parsing JSON query string " + json, ex);
+        }
+
         if ( o instanceof Map ) {
             @SuppressWarnings({ "unchecked", "rawtypes" }) Map<String, List<String>>
params =
                     ClassUtils.cast( MapUtils.toMapList( ( Map ) o ) );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dc12e8b6/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/JsonUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/JsonUtils.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/JsonUtils.java
deleted file mode 100644
index f44be17..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/JsonUtils.java
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.index.utils;
-
-
-import java.io.File;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.usergrid.persistence.index.exceptions.JsonReadException;
-import org.apache.usergrid.persistence.index.exceptions.JsonWriteException;
-
-import com.fasterxml.jackson.core.io.JsonStringEncoder;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.dataformat.smile.SmileFactory;
-
-//import org.codehaus.jackson.JsonNode;
-//import org.codehaus.jackson.io.JsonStringEncoder;
-//import org.codehaus.jackson.map.ObjectMapper;
-//import org.codehaus.jackson.map.SerializationConfig.Feature;
-//import org.codehaus.jackson.smile.SmileFactory;
-
-
-public class JsonUtils {
-
-    private static final Logger LOG = LoggerFactory.getLogger( JsonUtils.class );
-
-    static ObjectMapper mapper = new ObjectMapper();
-
-    static SmileFactory smile = new SmileFactory();
-
-    static ObjectMapper smileMapper = new ObjectMapper( smile );
-
-    private static ObjectMapper indentObjectMapper = new ObjectMapper();
-
-
-    static {
-        indentObjectMapper.getSerializationConfig().with( SerializationFeature.INDENT_OUTPUT);
-    }
-
-
-    /** Converts object to JSON string, throws runtime exception JsonWriteException on failure.
*/
-    public static String mapToJsonString( Object obj ) {
-        try {
-            return mapper.writeValueAsString( obj );
-        }
-        catch ( Throwable t ) {
-            LOG.debug( "Error generating JSON", t );
-            throw new JsonWriteException( "Error generating JSON", t );
-        }
-    }
-
-
-    /** Converts object to JSON string, throws runtime exception JsonWriteException on failure.
*/
-    public static String mapToFormattedJsonString( Object obj ) {
-        try {
-            return indentObjectMapper.writeValueAsString( obj );
-        }
-        catch ( Throwable t ) {
-            LOG.debug( "Error generating JSON", t );
-            throw new JsonWriteException( "Error generating JSON", t );
-        }
-    }
-
-
-    /** Parses JSON string  and returns object, throws runtime exception JsonReadException
on failure. */
-    public static Object parse( String json ) {
-        try {
-            return mapper.readValue( json, Object.class );
-        }
-        catch ( Throwable t ) {
-            LOG.debug( "Error parsing JSON", t );
-            throw new JsonReadException( "Error parsing JSON", t );
-        }
-    }
-
-
-    public static String quoteString( String s ) {
-        JsonStringEncoder encoder = new JsonStringEncoder();
-        return new String( encoder.quoteAsUTF8( s ) );
-    }
-
-
-    public static ByteBuffer toByteBuffer( Object obj ) {
-        if ( obj == null ) {
-            return null;
-        }
-
-        byte[] bytes = null;
-        try {
-            bytes = smileMapper.writeValueAsBytes( obj );
-        }
-        catch ( Exception e ) {
-            LOG.error( "Error getting SMILE bytes", e );
-        }
-        if ( bytes != null ) {
-            return ByteBuffer.wrap( bytes );
-        }
-        return null;
-    }
-
-
-    public static Object fromByteBuffer( ByteBuffer byteBuffer ) {
-        return fromByteBuffer( byteBuffer, Object.class );
-    }
-
-
-    public static Object fromByteBuffer( ByteBuffer byteBuffer, Class<?> clazz ) {
-        if ( ( byteBuffer == null ) || !byteBuffer.hasRemaining() ) {
-            return null;
-        }
-        if ( clazz == null ) {
-            clazz = Object.class;
-        }
-
-        Object obj = null;
-        try {
-            obj = smileMapper.readValue( byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(),
-                    byteBuffer.remaining(), clazz );
-        }
-        catch ( Exception e ) {
-            LOG.error( "Error parsing SMILE bytes", e );
-        }
-        return obj;
-    }
-
-
-    public static JsonNode toJsonNode( Object obj ) {
-        if ( obj == null ) {
-            return null;
-        }
-        return mapper.convertValue( obj, JsonNode.class );
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public static Map<String, Object> toJsonMap( Object obj ) {
-        if ( obj == null ) {
-            return null;
-        }
-
-        return ( Map<String, Object> ) mapper.convertValue( obj, Map.class );
-    }
-
-
-    private static UUID tryConvertToUUID( Object o ) {
-        if ( o instanceof String ) {
-            String s = ( String ) o;
-            if ( s.length() == 36 ) {
-                try {
-                    return UUID.fromString( s );
-                }
-                catch ( IllegalArgumentException e ) {
-                    LOG.warn( "Argument to UUID.fromString({}) was invalid.", s, e );
-                }
-            }
-        }
-        return null;
-    }
-
-
-    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;
-    }
-
-
-//    public static Object select( Object obj, String path ) {
-//        return select( obj, path, false );
-//    }
-//
-//
-//    public static Object select( Object obj, String path, boolean buildResultTree ) {
-//
-//        if ( obj == null ) {
-//            return null;
-//        }
-//
-//        if ( org.apache.commons.lang.StringUtils.isBlank( path ) ) {
-//            return obj;
-//        }
-//
-//        String segment = stringOrSubstringBeforeFirst( path, '.' );
-//        String remaining = substringAfter( path, "." );
-//
-//        if ( obj instanceof Map ) {
-//            Map<?, ?> map = ( Map<?, ?> ) obj;
-//            Object child = map.get( segment );
-//            Object result = select( child, remaining, buildResultTree );
-//            if ( result != null ) {
-//                if ( buildResultTree ) {
-//                    Map<Object, Object> results = new LinkedHashMap<Object, Object>();
-//                    results.put( segment, result );
-//                    return results;
-//                }
-//                else {
-//                    return result;
-//                }
-//            }
-//            return null;
-//        }
-//        if ( obj instanceof List ) {
-//            List<Object> results = new ArrayList<Object>();
-//            List<?> list = ( List<?> ) obj;
-//            for ( Object i : list ) {
-//                Object result = select( i, path, buildResultTree );
-//                if ( result != null ) {
-//                    results.add( result );
-//                }
-//            }
-//            if ( !results.isEmpty() ) {
-//                return results;
-//            }
-//            return null;
-//        }
-//
-//        if ( obj instanceof Entity ) {
-//            Object child = ( ( Entity ) obj ).getProperty( segment );
-//            Object result = select( child, remaining, buildResultTree );
-//            if ( result != null ) {
-//                if ( buildResultTree ) {
-//                    Map<Object, Object> results = new LinkedHashMap<Object, Object>();
-//                    results.put( segment, result );
-//                    return results;
-//                }
-//                else {
-//                    return result;
-//                }
-//            }
-//            else {
-//                return result;
-//            }
-//        }
-//
-//        return obj;
-//    }
-
-
-    public static Object loadFromFilesystem( String filename ) {
-        Object json = null;
-        try {
-            File file = new File( filename );
-            json = mapper.readValue( file, Object.class );
-        }
-        catch ( Exception e ) {
-            LOG.error( "Error loading JSON", e );
-        }
-        return json;
-    }
-}


Mime
View raw message