polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [1/6] zest-qi4j git commit: Add an Option to serialize Maps in a more condense format; "map" : { "name" : "Niclas", "country" : "Malaysia" } instead of "map" : [ { "key" : "name", "value" : "Niclas" }, { "key" : "country", "value" : "Malaysia
Date Wed, 17 Jun 2015 03:10:07 GMT
Repository: zest-qi4j
Updated Branches:
  refs/heads/develop 813aacf33 -> b86b66d4e


Add an Option to serialize Maps in a more condense format;
     "map" : {  "name" : "Niclas", "country" : "Malaysia" }
 instead of
     "map" : [ { "key" : "name", "value" : "Niclas" }, { "key" : "country", "value" : "Malaysia"
} ]


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/6b068deb
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/6b068deb
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/6b068deb

Branch: refs/heads/develop
Commit: 6b068deb3a24788f6f4f32c8c68cb49efad72aaa
Parents: 813aacf
Author: Niclas Hedhman <niclas@hedhman.org>
Authored: Wed Jun 17 10:32:46 2015 +0800
Committer: Niclas Hedhman <niclas@hedhman.org>
Committed: Wed Jun 17 10:32:46 2015 +0800

----------------------------------------------------------------------
 .../qi4j/spi/value/ValueSerializerAdapter.java  | 46 +++++++++++++-------
 1 file changed, 31 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/6b068deb/core/spi/src/main/java/org/qi4j/spi/value/ValueSerializerAdapter.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/qi4j/spi/value/ValueSerializerAdapter.java b/core/spi/src/main/java/org/qi4j/spi/value/ValueSerializerAdapter.java
index 71717db..3625a21 100644
--- a/core/spi/src/main/java/org/qi4j/spi/value/ValueSerializerAdapter.java
+++ b/core/spi/src/main/java/org/qi4j/spi/value/ValueSerializerAdapter.java
@@ -48,7 +48,6 @@ import org.qi4j.api.value.ValueSerializationException;
 import org.qi4j.api.value.ValueSerializer;
 import org.qi4j.functional.Function;
 import org.qi4j.functional.Function2;
-import org.qi4j.spi.Qi4jSPI;
 
 import static org.qi4j.functional.Iterables.first;
 
@@ -417,6 +416,7 @@ public abstract class ValueSerializerAdapter<OutputType>
 
         onObjectStart( output );
 
+        //noinspection ConstantConditions
         if( options.getBoolean( Options.INCLUDE_TYPE_INFO ) && !rootPass )
         {
             onFieldStart( output, "_type" );
@@ -517,26 +517,42 @@ public abstract class ValueSerializerAdapter<OutputType>
     {
         @SuppressWarnings( "unchecked" )
         Map<Object, Object> map = (Map<Object, Object>) object;
-        onArrayStart( output );
-        for( Map.Entry<Object, Object> entry : map.entrySet() )
+        if( options.getBoolean( Options.MAP_ENTRIES_AS_OBJECTS ) )
         {
             onObjectStart( output );
+            for( Map.Entry<Object, Object> entry : map.entrySet() )
+            {
+                onFieldStart( output, entry.getKey().toString() );
+                onValueStart( output );
+                doSerialize( options, entry.getValue(), output, false );
+                onValueEnd( output );
+                onFieldEnd( output );
+            }
+            onObjectEnd( output );
+        }
+        else
+        {
+            onArrayStart( output );
+            for( Map.Entry<Object, Object> entry : map.entrySet() )
+            {
+                onObjectStart( output );
 
-            onFieldStart( output, "key" );
-            onValueStart( output );
-            onValue( output, entry.getKey().toString() );
-            onValueEnd( output );
-            onFieldEnd( output );
+                onFieldStart( output, "key" );
+                onValueStart( output );
+                onValue( output, entry.getKey().toString() );
+                onValueEnd( output );
+                onFieldEnd( output );
 
-            onFieldStart( output, "value" );
-            onValueStart( output );
-            doSerialize( options, entry.getValue(), output, false );
-            onValueEnd( output );
-            onFieldEnd( output );
+                onFieldStart( output, "value" );
+                onValueStart( output );
+                doSerialize( options, entry.getValue(), output, false );
+                onValueEnd( output );
+                onFieldEnd( output );
 
-            onObjectEnd( output );
+                onObjectEnd( output );
+            }
+            onArrayEnd( output );
         }
-        onArrayEnd( output );
     }
 
     private void serializeBase64Serializable( Object object, OutputType output )


Mime
View raw message