Repository: olingo-odata4 Updated Branches: refs/heads/master 9e67d0e3e -> 5255c336e
[OLINGO-1033] Add # for primitive type annotations Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/5255c336 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/5255c336 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/5255c336 Branch: refs/heads/master Commit: 5255c336ebde38493337bd6761b49a80654a3289 Parents: 9e67d0e Author: Christian Amend <[email protected]> Authored: Tue Oct 18 15:58:13 2016 +0200 Committer: Christian Amend <[email protected]> Committed: Tue Oct 18 15:58:13 2016 +0200 ---------------------------------------------------------------------- .../json/EdmAssistedJsonSerializer.java | 24 ++++++++++++++-- .../json/EdmAssistedJsonSerializerTest.java | 30 ++++++++++---------- 2 files changed, 36 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5255c336/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java index 66cc15c..3d86953 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java @@ -385,9 +385,7 @@ public class EdmAssistedJsonSerializer implements EdmAssistedSerializer { } } if (typeName != null) { - json.writeStringField( - name + Constants.JSON_TYPE, - new EdmTypeInfo.Builder().setTypeExpression(typeName).build().external()); + json.writeStringField(name + Constants.JSON_TYPE, constructTypeExpression(typeName)); } } @@ -398,4 +396,24 @@ public class EdmAssistedJsonSerializer implements EdmAssistedSerializer { json.writeFieldName(name); value(json, valuable, type, edmProperty); } + + private String constructTypeExpression(String typeName) { + EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName).build(); + StringBuilder stringBuilder = new StringBuilder(); + + if (typeInfo.isCollection()) { + stringBuilder.append("#Collection("); + } else { + stringBuilder.append('#'); + } + + stringBuilder.append(typeInfo.isPrimitiveType() ? typeInfo.getFullQualifiedName().getName() : typeInfo + .getFullQualifiedName().getFullQualifiedNameAsString()); + + if (typeInfo.isCollection()) { + stringBuilder.append(')'); + } + + return stringBuilder.toString(); + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5255c336/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializerTest.java index 030a5eb..808e459 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializerTest.java @@ -69,7 +69,7 @@ public class EdmAssistedJsonSerializerTest { EntityCollection entityCollection = new EntityCollection(); entityCollection.getEntities().add(entity); Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1)\"," - + "\"value\":[{\"@odata.id\":null,\"[email protected]\":\"Single\",\"Property1\":1.25}]}", + + "\"value\":[{\"@odata.id\":null,\"[email protected]\":\"#Single\",\"Property1\":1.25}]}", serialize(serializer, metadata, null, entityCollection, null)); } @@ -85,7 +85,7 @@ public class EdmAssistedJsonSerializerTest { entityCollection.getEntities().add(entity); Assert.assertEquals("{\"@odata.context\":\"$metadata#ESTwoPrim\",\"value\":[{\"@odata.id\":null," + "\"PropertyInt16\":1,\"PropertyString\":\"test\"," - + "\"[email protected]\":\"SByte\",\"AdditionalProperty\":42}]}", + + "\"[email protected]\":\"#SByte\",\"AdditionalProperty\":42}]}", serialize(serializer, metadata, entitySet, entityCollection, null)); } @@ -111,9 +111,9 @@ public class EdmAssistedJsonSerializerTest { + "\"@odata.count\":2," + "\"value\":[{\"@odata.id\":null," + "\"Property0\":null," - + "\"[email protected]\":\"Int32\",\"Property1\":1," - + "\"[email protected]\":\"Date\",\"Property2\":\"2000-02-29\"," - + "\"[email protected]\":\"DateTimeOffset\",\"Property3\":\"2000-02-29T00:00:00Z\"," + + "\"[email protected]\":\"#Int32\",\"Property1\":1," + + "\"[email protected]\":\"#Date\",\"Property2\":\"2000-02-29\"," + + "\"[email protected]\":\"#DateTimeOffset\",\"Property3\":\"2000-02-29T00:00:00Z\"," + "\"[email protected]\":\"#Collection(Boolean)\",\"Property4\":[true,false,null]}]," + "\"@odata.nextLink\":\"nextLink\"}", serialize(serializer, metadata, null, entityCollection, null)); @@ -131,9 +131,9 @@ public class EdmAssistedJsonSerializerTest { "{\"@odata.context\":\"$metadata#EntitySet(Property1,Property2,Property3)\"," + "\"@odata.count\":\"3\"," + "\"value\":[{\"@odata.id\":null," - + "\"[email protected]\":\"Int64\",\"Property1\":\"-9223372036854775808\"," - + "\"[email protected]\":\"Decimal\",\"Property2\":\"922337203.6854775807\"," - + "\"[email protected]\":\"Byte\",\"Property3\":20}]}", + + "\"[email protected]\":\"#Int64\",\"Property1\":\"-9223372036854775808\"," + + "\"[email protected]\":\"#Decimal\",\"Property2\":\"922337203.6854775807\"," + + "\"[email protected]\":\"#Byte\",\"Property3\":20}]}", serialize( oData.createEdmAssistedSerializer( ContentType.create(ContentType.JSON, ContentType.PARAMETER_IEEE754_COMPATIBLE, "true")), @@ -159,10 +159,10 @@ public class EdmAssistedJsonSerializerTest { entityCollection.getEntities().add(entity); Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1,Property2)\"," + "\"value\":[{\"@odata.id\":null," - + "\"[email protected]\":\"Int64\",\"Property1\":1," + + "\"[email protected]\":\"#Int64\",\"Property1\":1," + "\"Property2\":{\"@odata.type\":\"#Namespace.ComplexType\"," - + "\"[email protected]\":\"Decimal\",\"Inner1\":0.00010," - + "\"[email protected]\":\"TimeOfDay\",\"Inner2\":\"13:00:59.999\"}}]}", + + "\"[email protected]\":\"#Decimal\",\"Inner1\":0.00010," + + "\"[email protected]\":\"#TimeOfDay\",\"Inner2\":\"13:00:59.999\"}}]}", serialize(serializer, metadata, null, entityCollection, null)); } @@ -222,10 +222,10 @@ public class EdmAssistedJsonSerializerTest { entityCollection.getEntities().add(entity); Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1,NavigationProperty(Related1))\"," + "\"value\":[{\"@odata.id\":null," - + "\"[email protected]\":\"Int16\",\"Property1\":1," + + "\"[email protected]\":\"#Int16\",\"Property1\":1," + "\"NavigationProperty\":[" - + "{\"@odata.id\":null,\"[email protected]\":\"Double\",\"Related1\":1.5}," - + "{\"@odata.id\":null,\"[email protected]\":\"Double\",\"Related1\":2.75}]}]}", + + "{\"@odata.id\":null,\"[email protected]\":\"#Double\",\"Related1\":1.5}," + + "{\"@odata.id\":null,\"[email protected]\":\"#Double\",\"Related1\":2.75}]}]}", serialize(serializer, metadata, null, entityCollection, "Property1,NavigationProperty(Related1)")); } @@ -271,7 +271,7 @@ public class EdmAssistedJsonSerializerTest { + "\"@odata.etag\":\"W/\\\"1000\\\"\"," + "\"@odata.type\":\"#Namespace.EntityType\"," + "\"@odata.id\":\"ID\"," - + "\"[email protected]\":\"Guid\",\"Property1\":\"12345678-abcd-1234-cdef-123456789012\"," + + "\"[email protected]\":\"#Guid\",\"Property1\":\"12345678-abcd-1234-cdef-123456789012\"," + "\"@odata.editLink\":\"editLink\"," + "\"@odata.mediaReadLink\":\"editLink/$value\"}]}", serialize(serializer, metadata, null, entityCollection, null));
