You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2016/10/18 14:00:08 UTC
olingo-odata4 git commit: [OLINGO-1033] Add # for primitive type
annotations
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 <ch...@sap.com>
Authored: Tue Oct 18 15:58:13 2016 +0200
Committer: Christian Amend <ch...@sap.com>
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,\"Property1@odata.type\":\"Single\",\"Property1\":1.25}]}",
+ + "\"value\":[{\"@odata.id\":null,\"Property1@odata.type\":\"#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\","
- + "\"AdditionalProperty@odata.type\":\"SByte\",\"AdditionalProperty\":42}]}",
+ + "\"AdditionalProperty@odata.type\":\"#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,"
- + "\"Property1@odata.type\":\"Int32\",\"Property1\":1,"
- + "\"Property2@odata.type\":\"Date\",\"Property2\":\"2000-02-29\","
- + "\"Property3@odata.type\":\"DateTimeOffset\",\"Property3\":\"2000-02-29T00:00:00Z\","
+ + "\"Property1@odata.type\":\"#Int32\",\"Property1\":1,"
+ + "\"Property2@odata.type\":\"#Date\",\"Property2\":\"2000-02-29\","
+ + "\"Property3@odata.type\":\"#DateTimeOffset\",\"Property3\":\"2000-02-29T00:00:00Z\","
+ "\"Property4@odata.type\":\"#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,"
- + "\"Property1@odata.type\":\"Int64\",\"Property1\":\"-9223372036854775808\","
- + "\"Property2@odata.type\":\"Decimal\",\"Property2\":\"922337203.6854775807\","
- + "\"Property3@odata.type\":\"Byte\",\"Property3\":20}]}",
+ + "\"Property1@odata.type\":\"#Int64\",\"Property1\":\"-9223372036854775808\","
+ + "\"Property2@odata.type\":\"#Decimal\",\"Property2\":\"922337203.6854775807\","
+ + "\"Property3@odata.type\":\"#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,"
- + "\"Property1@odata.type\":\"Int64\",\"Property1\":1,"
+ + "\"Property1@odata.type\":\"#Int64\",\"Property1\":1,"
+ "\"Property2\":{\"@odata.type\":\"#Namespace.ComplexType\","
- + "\"Inner1@odata.type\":\"Decimal\",\"Inner1\":0.00010,"
- + "\"Inner2@odata.type\":\"TimeOfDay\",\"Inner2\":\"13:00:59.999\"}}]}",
+ + "\"Inner1@odata.type\":\"#Decimal\",\"Inner1\":0.00010,"
+ + "\"Inner2@odata.type\":\"#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,"
- + "\"Property1@odata.type\":\"Int16\",\"Property1\":1,"
+ + "\"Property1@odata.type\":\"#Int16\",\"Property1\":1,"
+ "\"NavigationProperty\":["
- + "{\"@odata.id\":null,\"Related1@odata.type\":\"Double\",\"Related1\":1.5},"
- + "{\"@odata.id\":null,\"Related1@odata.type\":\"Double\",\"Related1\":2.75}]}]}",
+ + "{\"@odata.id\":null,\"Related1@odata.type\":\"#Double\",\"Related1\":1.5},"
+ + "{\"@odata.id\":null,\"Related1@odata.type\":\"#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\","
- + "\"Property1@odata.type\":\"Guid\",\"Property1\":\"12345678-abcd-1234-cdef-123456789012\","
+ + "\"Property1@odata.type\":\"#Guid\",\"Property1\":\"12345678-abcd-1234-cdef-123456789012\","
+ "\"@odata.editLink\":\"editLink\","
+ "\"@odata.mediaReadLink\":\"editLink/$value\"}]}",
serialize(serializer, metadata, null, entityCollection, null));