You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/04/09 17:04:01 UTC

[2/2] git commit: Uniforming the type expression (de)serialization

Uniforming the type expression (de)serialization


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/9f96234e
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/9f96234e
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/9f96234e

Branch: refs/heads/master
Commit: 9f96234e69918d04440a927cc732917044e81027
Parents: 0612eab
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Wed Apr 9 17:03:50 2014 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Wed Apr 9 17:03:50 2014 +0200

----------------------------------------------------------------------
 .../it/v4/BoundOperationInvokeTestITCase.java   | 45 ++++++--------------
 .../core/it/v4/EntityRetrieveTestITCase.java    |  2 +-
 .../it/v4/OperationImportInvokeTestITCase.java  |  2 +-
 .../olingo/client/core/v4/EntityTest.java       |  2 +-
 .../commons/core/data/AtomDeserializer.java     |  5 +--
 .../commons/core/data/AtomSerializer.java       | 20 +++------
 .../core/data/JSONEntryDeserializer.java        |  8 ++--
 .../commons/core/data/JSONEntrySerializer.java  |  4 +-
 .../core/data/JSONPropertyDeserializer.java     |  6 ++-
 .../olingo/commons/core/edm/EdmTypeInfo.java    | 44 ++++++++++++++++++-
 10 files changed, 77 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9f96234e/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java
index d46ee3e..6bb9307 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java
@@ -50,7 +50,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
 import org.junit.Assume;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -101,8 +100,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     ODataOperation boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount");
     assertNotNull(boundOp);
 
-    EdmFunction func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()),
-            new EdmTypeInfo.Builder().setTypeExpression(entity.getTypeName().toString()).build().getFullQualifiedName(),
+    EdmFunction func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(),
             false, null);
     assertNotNull(func);
 
@@ -124,9 +122,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails");
     assertNotNull(boundOp);
 
-    func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()),
-            new EdmTypeInfo.Builder().setTypeExpression(entity.getTypeName().toString()).build().getFullQualifiedName(),
-            false, null);
+    func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
     assertNotNull(func);
 
     final ODataPrimitiveValue count = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(1);
@@ -153,9 +149,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetRelatedProduct");
     assertNotNull(boundOp);
 
-    func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()),
-            new EdmTypeInfo.Builder().setTypeExpression(entity.getTypeName().toString()).build().getFullQualifiedName(),
-            false, null);
+    func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
     assertNotNull(func);
 
     final ODataInvokeRequest<ODataEntity> getRelatedProductReq =
@@ -165,7 +159,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     try {
       final ODataEntity getRelatedProductRes = getRelatedProductReq.execute().getBody();
       assertNotNull(getRelatedProductRes);
-      assertEquals("#Microsoft.Test.OData.Services.ODataWCFService.Product",
+      assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Product",
               getRelatedProductRes.getTypeName().toString());
       assertEquals(6, getRelatedProductRes.getProperty("ProductID").getPrimitiveValue().toCastValue(Integer.class), 0);
     } catch (Exception e) {
@@ -183,9 +177,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetDefaultPI");
     assertNotNull(boundOp);
 
-    func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()),
-            new EdmTypeInfo.Builder().setTypeExpression(entity.getTypeName().toString()).build().getFullQualifiedName(),
-            false, null);
+    func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
     assertNotNull(func);
 
     final ODataInvokeRequest<ODataEntity> getDefaultPIReq =
@@ -193,7 +185,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     getDefaultPIReq.setFormat(format);
     final ODataEntity getDefaultPIRes = getDefaultPIReq.execute().getBody();
     assertNotNull(getDefaultPIRes);
-    assertEquals("#Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument",
+    assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument",
             getDefaultPIRes.getTypeName().toString());
     assertEquals(101901,
             getDefaultPIRes.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
@@ -202,9 +194,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetAccountInfo");
     assertNotNull(boundOp);
 
-    func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()),
-            new EdmTypeInfo.Builder().setTypeExpression(entity.getTypeName().toString()).build().getFullQualifiedName(),
-            false, null);
+    func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
     assertNotNull(func);
 
     final ODataInvokeRequest<ODataProperty> getAccountInfoReq =
@@ -228,9 +218,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetActualAmount");
     assertNotNull(boundOp);
 
-    func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()),
-            new EdmTypeInfo.Builder().setTypeExpression(entity.getTypeName().toString()).build().getFullQualifiedName(),
-            false, null);
+    func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
     assertNotNull(func);
 
     final ODataPrimitiveValue bonusRate = getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(1.1);
@@ -270,9 +258,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     ODataOperation boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.IncreaseRevenue");
     assertNotNull(boundOp);
 
-    EdmAction act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()),
-            new EdmTypeInfo.Builder().setTypeExpression(entity.getTypeName().toString()).build().getFullQualifiedName(),
-            false);
+    EdmAction act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
     assertNotNull(act);
 
     final ODataPrimitiveValue increaseValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
@@ -296,9 +282,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.AddAccessRight");
     assertNotNull(boundOp);
 
-    act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()),
-            new EdmTypeInfo.Builder().setTypeExpression(entity.getTypeName().toString()).build().getFullQualifiedName(),
-            false);
+    act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
     assertNotNull(act);
 
     final ODataEnumValue accessRight = getClient().getObjectFactory().
@@ -323,8 +307,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     assertNotNull(boundOp);
 
     act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()),
-            edm.getEntityType(new EdmTypeInfo.Builder().setTypeExpression(entity.getTypeName().toString()).build().
-                    getFullQualifiedName()).getBaseType().getFullQualifiedName(), false);
+            edm.getEntityType(entity.getTypeName()).getBaseType().getFullQualifiedName(), false);
     assertNotNull(act);
 
     final ODataCollectionValue<org.apache.olingo.commons.api.domain.v4.ODataValue> addresses =
@@ -361,9 +344,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.RefreshDefaultPI");
     assertNotNull(boundOp);
 
-    act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()),
-            new EdmTypeInfo.Builder().setTypeExpression(entity.getTypeName().toString()).build().getFullQualifiedName(),
-            false);
+    act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
     assertNotNull(act);
 
     final ODataPrimitiveValue newDate = getClient().getObjectFactory().newPrimitiveValueBuilder().
@@ -374,7 +355,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
     getDefaultPIReq.setFormat(format);
     final ODataEntity getDefaultPIRes = getDefaultPIReq.execute().getBody();
     assertNotNull(getDefaultPIRes);
-    assertEquals("#Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument",
+    assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument",
             getDefaultPIRes.getTypeName().toString());
     assertEquals(101901,
             getDefaultPIRes.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9f96234e/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
index d55313f..4923015 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
@@ -67,7 +67,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
     final CommonODataEntity entity = res.getBody();
 
     assertNotNull(entity);
-    assertEquals("#Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
+    assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
     assertEquals(getServiceRoot() + "/Customers(PersonID=1)", entity.getEditLink().toASCIIString());
 
     assertEquals(3, entity.getNavigationLinks().size());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9f96234e/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java
index d65e7f9..989c152 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java
@@ -113,7 +113,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase {
     person2Req.setFormat(format);
     final ODataEntity person2 = person2Req.execute().getBody();
     assertNotNull(person2);
-    assertEquals("#Microsoft.Test.OData.Services.ODataWCFService.Customer", person2.getTypeName().toString());
+    assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", person2.getTypeName().toString());
     assertEquals(1, person2.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
 
     // GetPerson

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9f96234e/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java
index 3db8436..5707985 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java
@@ -53,7 +53,7 @@ public class EntityTest extends AbstractTest {
             getClient().getDeserializer().toEntry(input, format).getObject());
     assertNotNull(entity);
 
-    assertEquals("#Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
+    assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
 
     final ODataProperty birthday = entity.getProperty("Birthday");
     assertTrue(birthday.hasPrimitiveValue());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9f96234e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java
index 71c658c..850611b 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java
@@ -36,7 +36,6 @@ import org.apache.olingo.commons.api.data.Value;
 import org.apache.olingo.commons.api.domain.ODataOperation;
 import org.apache.olingo.commons.api.domain.ODataPropertyType;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
 import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.commons.core.data.v3.XMLLinkCollectionImpl;
@@ -247,7 +246,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
               : new EdmTypeInfo.Builder().setTypeExpression(typeAttrValue).build();
 
       if (typeInfo != null) {
-        property.setType(typeInfo.getTypeExpression());
+        property.setType(typeInfo.internal());
       }
 
       final ODataPropertyType propType = typeInfo == null
@@ -452,7 +451,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
           } else if (Constants.QNAME_ATOM_ELEM_CATEGORY.equals(event.asStartElement().getName())) {
             final Attribute term = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_TERM));
             if (term != null) {
-              entry.setType(term.getValue());
+              entry.setType(new EdmTypeInfo.Builder().setTypeExpression(term.getValue()).build().internal());
             }
           } else if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) {
             final LinkImpl link = new LinkImpl();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9f96234e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
index d0e8587..aef5950 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
@@ -94,21 +94,10 @@ public class AtomSerializer extends AbstractAtomDealer {
     }
 
     if (StringUtils.isNotBlank(property.getType())) {
-      String type = property.getType();
-      if (version.compareTo(ODataServiceVersion.V40) >= 0) {
-        final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build();
-        if (typeInfo.isPrimitiveType()) {
-          if (typeInfo.isCollection()) {
-            type = "#Collection(" + typeInfo.getFullQualifiedName().getName() + ")";
-          } else {
-            type = typeInfo.getFullQualifiedName().getName();
-          }
-        } else {
-          type = "#" + property.getType();
-        }
-      }
+      final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build();
       writer.writeAttribute(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
-              Constants.ATTR_TYPE, type);
+              Constants.ATTR_TYPE,
+              new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build().external(version));
     }
 
     if (property.getValue().isNull()) {
@@ -223,7 +212,8 @@ public class AtomSerializer extends AbstractAtomDealer {
 
     writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY);
     writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, version.getNamespaceMap().get(ODataServiceVersion.NS_SCHEME));
-    writer.writeAttribute(Constants.ATOM_ATTR_TERM, entry.getType());
+    writer.writeAttribute(Constants.ATOM_ATTR_TERM,
+            new EdmTypeInfo.Builder().setTypeExpression(entry.getType()).build().external(version));
     writer.writeEndElement();
 
     if (entry instanceof AbstractODataObject) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9f96234e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java
index f2b0177..9fddf28 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java
@@ -35,8 +35,8 @@ import org.apache.olingo.commons.api.data.Container;
 import org.apache.olingo.commons.api.data.Link;
 import org.apache.olingo.commons.api.domain.ODataLinkType;
 import org.apache.olingo.commons.api.domain.ODataOperation;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.core.edm.EdmTypeInfo;
 
 /**
  * Reads JSON string into an entry.
@@ -87,7 +87,7 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp
     }
 
     if (tree.hasNonNull(jsonType)) {
-      entry.setType(tree.get(jsonType).textValue());
+      entry.setType(new EdmTypeInfo.Builder().setTypeExpression(tree.get(jsonType).textValue()).build().internal());
       tree.remove(jsonType);
     }
 
@@ -183,7 +183,9 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp
       } else {
         final JSONPropertyImpl property = new JSONPropertyImpl();
         property.setName(field.getKey());
-        property.setType(type);
+        property.setType(type == null
+                ? null
+                : new EdmTypeInfo.Builder().setTypeExpression(type).build().internal());
         type = null;
 
         value(property, field.getValue(), parser.getCodec());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9f96234e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java
index b7139d3..626ed14 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java
@@ -27,6 +27,7 @@ import org.apache.olingo.commons.api.data.Entry;
 import org.apache.olingo.commons.api.data.Link;
 import org.apache.olingo.commons.api.data.Property;
 import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.core.edm.EdmTypeInfo;
 
 /**
  * Writes out JSON string from an entry.
@@ -40,7 +41,8 @@ public class JSONEntrySerializer extends AbstractJsonSerializer<JSONEntryImpl> {
     jgen.writeStartObject();
 
     if (StringUtils.isNotBlank(entry.getType())) {
-      jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE), entry.getType());
+      jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE),
+              new EdmTypeInfo.Builder().setTypeExpression(entry.getType()).build().external(version));
     }
 
     if (entry.getId() != null) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9f96234e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java
index d640a60..6d8f0e2 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java
@@ -27,6 +27,7 @@ import java.net.URI;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.olingo.commons.api.Constants;
 import org.apache.olingo.commons.api.data.Container;
+import org.apache.olingo.commons.core.edm.EdmTypeInfo;
 
 /**
  * Parse JSON string into <tt>JSONPropertyImpl</tt>.
@@ -58,14 +59,15 @@ public class JSONPropertyDeserializer extends AbstractJsonDeserializer<JSONPrope
       tree.remove(Constants.JSON_CONTEXT);
     } else if (tree.hasNonNull(Constants.JSON_METADATA)) {
       contextURL = URI.create(tree.get(Constants.JSON_METADATA).textValue());
-      property.setType(StringUtils.substringAfterLast(contextURL.toASCIIString(), "#"));
+      property.setType(new EdmTypeInfo.Builder().
+              setTypeExpression(StringUtils.substringAfterLast(contextURL.toASCIIString(), "#")).build().internal());
       tree.remove(Constants.JSON_METADATA);
     } else {
       contextURL = null;
     }
 
     if (tree.has(jsonType)) {
-      property.setType(tree.get(jsonType).asText());
+      property.setType(new EdmTypeInfo.Builder().setTypeExpression(tree.get(jsonType).textValue()).build().internal());
     }
 
     if (tree.has(Constants.JSON_NULL) && tree.get(Constants.JSON_NULL).asBoolean()) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9f96234e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
index 97b01b3..37d52dd 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
@@ -26,6 +26,7 @@ import org.apache.olingo.commons.api.edm.EdmEnumType;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -137,8 +138,47 @@ public class EdmTypeInfo {
     }
   }
 
-  public String getTypeExpression() {
-    return typeExpression;
+  public String internal() {
+    final StringBuilder deserialize = new StringBuilder();
+
+    if (isCollection()) {
+      deserialize.append("Collection(");
+    }
+
+    deserialize.append(getFullQualifiedName().toString());
+
+    if (isCollection()) {
+      deserialize.append(")");
+    }
+
+    return deserialize.toString();
+  }
+
+  public String external(final ODataServiceVersion version) {
+    final StringBuilder serialize = new StringBuilder();
+
+    if (isCollection()) {
+      if (version.compareTo(ODataServiceVersion.V40) >= 0) {
+        serialize.append('#');
+      }
+      serialize.append("Collection(");
+    }
+
+    if (isPrimitiveType() && version.compareTo(ODataServiceVersion.V40) >= 0) {
+      serialize.append(getFullQualifiedName().getName());
+    } else {
+      serialize.append(getFullQualifiedName().toString());
+    }
+
+    if (isCollection()) {
+      serialize.append(")");
+    }
+
+    if (version.compareTo(ODataServiceVersion.V40) >= 0 && !isPrimitiveType() && !isCollection()) {
+      serialize.insert(0, '#');
+    }
+
+    return serialize.toString();
   }
 
   public boolean isCollection() {