TINKERPOP-1427 Coerced Map.Entry to a Map with single entry
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/010b4348 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/010b4348 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/010b4348 Branch: refs/heads/TINKERPOP-1552-master Commit: 010b43488b199fa522f6d13ae6168788bfd6afb8 Parents: 7fd0e80 Author: Stephen Mallette <sp...@genoprime.com> Authored: Mon Jul 10 12:50:28 2017 -0400 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Thu Jul 13 13:01:35 2017 -0400 ---------------------------------------------------------------------- .../structure/io/graphson/GraphSONModule.java | 2 -- .../io/graphson/GraphSONTypeSerializerV3d0.java | 6 ++-- .../io/graphson/JavaUtilSerializersV3d0.java | 32 ++++---------------- .../ser/GraphSONMessageSerializerV3d0Test.java | 5 +-- .../server/GremlinServerHttpIntegrateTest.java | 2 +- 5 files changed, 12 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/010b4348/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java index 00bec01..9354eac 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java @@ -125,7 +125,6 @@ abstract class GraphSONModule extends TinkerPopJacksonModule { put(Double.class, "Double"); put(Float.class, "Float"); - put(Map.Entry.class, "Entry"); put(Map.class, "Map"); put(List.class, "List"); put(Set.class, "Set"); @@ -249,7 +248,6 @@ abstract class GraphSONModule extends TinkerPopJacksonModule { addDeserializer(Tree.class, new GraphSONSerializersV3d0.TreeJacksonDeserializer()); // java.util - addDeserializer(Map.Entry.class, new JavaUtilSerializersV3d0.MapEntryJacksonDeserializer()); addDeserializer(Map.class, new JavaUtilSerializersV3d0.MapJacksonDeserializer()); addDeserializer(List.class, new JavaUtilSerializersV3d0.ListJacksonDeserializer()); addDeserializer(Set.class, new JavaUtilSerializersV3d0.SetJacksonDeserializer()); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/010b4348/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializerV3d0.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializerV3d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializerV3d0.java index f3b7afa..6d47ad9 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializerV3d0.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializerV3d0.java @@ -61,7 +61,7 @@ public class GraphSONTypeSerializerV3d0 extends AbstractGraphSONTypeSerializer { @Override public void writeTypePrefixForObject(final Object o, final JsonGenerator jsonGenerator) throws IOException { - if (o instanceof Map || o instanceof Map.Entry) { + if (o instanceof Map) { writeTypePrefix(jsonGenerator, getTypeIdResolver().idFromValueAndType(o, getClassFromObject(o))); jsonGenerator.writeStartArray(); } else { @@ -71,7 +71,7 @@ public class GraphSONTypeSerializerV3d0 extends AbstractGraphSONTypeSerializer { @Override public void writeTypeSuffixForObject(final Object o, final JsonGenerator jsonGenerator) throws IOException { - if (o instanceof Map || o instanceof Map.Entry) { + if (o instanceof Map) { jsonGenerator.writeEndArray(); writeTypeSuffix(jsonGenerator); } else { @@ -108,8 +108,6 @@ public class GraphSONTypeSerializerV3d0 extends AbstractGraphSONTypeSerializer { final Class mapped; if (Map.class.isAssignableFrom(c)) mapped = Map.class; - else if (Map.Entry.class.isAssignableFrom(c)) - mapped = Map.Entry.class; else if (List.class.isAssignableFrom(c)) mapped = List.class; else if (Set.class.isAssignableFrom(c)) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/010b4348/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/JavaUtilSerializersV3d0.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/JavaUtilSerializersV3d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/JavaUtilSerializersV3d0.java index 8298ce7..f5c4da8 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/JavaUtilSerializersV3d0.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/JavaUtilSerializersV3d0.java @@ -26,7 +26,6 @@ import org.apache.tinkerpop.shaded.jackson.databind.DeserializationContext; import org.apache.tinkerpop.shaded.jackson.databind.SerializerProvider; import org.apache.tinkerpop.shaded.jackson.databind.deser.std.StdDeserializer; import org.apache.tinkerpop.shaded.jackson.databind.jsontype.TypeSerializer; -import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdScalarSerializer; import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer; import java.io.IOException; @@ -70,6 +69,9 @@ final class JavaUtilSerializersV3d0 { } } + /** + * Coerces {@code Map.Entry} to a {@code Map} with a single entry in it. + */ final static class MapEntryJacksonSerializer extends StdSerializer<Map.Entry> { public MapEntryJacksonSerializer() { @@ -79,16 +81,15 @@ final class JavaUtilSerializersV3d0 { @Override public void serialize(final Map.Entry entry, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { - jsonGenerator.writeObject(entry.getKey()); - jsonGenerator.writeObject(entry.getValue()); + final Map<Object,Object> m = new HashMap<>(); + if (entry != null) m.put(entry.getKey(), entry.getValue()); + jsonGenerator.writeObject(m); } @Override public void serializeWithType(final Map.Entry entry, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException { - typeSerializer.writeTypePrefixForObject(entry, jsonGenerator); serialize(entry, jsonGenerator, serializerProvider); - typeSerializer.writeTypeSuffixForObject(entry, jsonGenerator); } } @@ -160,27 +161,6 @@ final class JavaUtilSerializersV3d0 { } } - static class MapEntryJacksonDeserializer extends StdDeserializer<Map.Entry> { - - protected MapEntryJacksonDeserializer() { - super(Map.Entry.class); - } - - @Override - public Map.Entry deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException { - final Map<Object,Object> m = new HashMap<>(); - - while (jsonParser.nextToken() != JsonToken.END_ARRAY) { - final Object key = deserializationContext.readValue(jsonParser, Object.class); - jsonParser.nextToken(); - final Object val = deserializationContext.readValue(jsonParser, Object.class); - m.put(key, val); - } - - return m.entrySet().iterator().next(); - } - } - static class SetJacksonDeserializer extends StdDeserializer<Set> { protected SetJacksonDeserializer() { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/010b4348/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV3d0Test.java ---------------------------------------------------------------------- diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV3d0Test.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV3d0Test.java index b4f49d7..4bd3f6f 100644 --- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV3d0Test.java +++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV3d0Test.java @@ -131,9 +131,10 @@ public class GraphSONMessageSerializerV3d0Test { final ResponseMessage response = convert(IteratorUtils.asList(map.entrySet())); assertCommon(response); - final List<Map.Entry<Object, Object>> deserializedEntries = (List<Map.Entry<Object, Object>>) response.getResult().getData(); + final List<Map<Object, Object>> deserializedEntries = (List<Map<Object, Object>>) response.getResult().getData(); assertEquals(3, deserializedEntries.size()); - deserializedEntries.forEach(e -> { + deserializedEntries.forEach(m -> { + final Map.Entry<Object,Object> e = m.entrySet().iterator().next(); if (e.getKey().equals("x")) assertEquals(1, e.getValue()); else if (e.getKey() instanceof Vertex && e.getKey().equals(v1)) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/010b4348/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java index a6e9c57..e452a22 100644 --- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java +++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java @@ -729,7 +729,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra assertEquals("application/json", response.getEntity().getContentType().getValue()); final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); - assertEquals("g:Entry", node.get("result").get("data").get(GraphSONTokens.VALUEPROP).get(0).get("@type").asText()); + assertEquals("g:Map", node.get("result").get("data").get(GraphSONTokens.VALUEPROP).get(0).get("@type").asText()); assertEquals(1, node.get("result").get("data").get(GraphSONTokens.VALUEPROP).get(0).get(GraphSONTokens.VALUEPROP).get(1).get(GraphSONTokens.VALUEPROP).asInt()); } }