From 1dd8c987bfa3d4943005f62047ec56424a2b33cf Mon Sep 17 00:00:00 2001 From: fmartelli Date: Thu, 15 May 2014 10:35:24 +0200 Subject: [PATCH] [OLINGO-260] fix type seraialization + opentype integration test extension --- .../org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java | 6 +++--- .../java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java | 4 ++++ .../org/apache/olingo/fit/v4/EntityCreateTestITCase.java | 2 +- .../olingo/commons/core/data/AbstractJsonSerializer.java | 2 +- .../commons/core/domain/AbstractODataCollectionValue.java | 2 +- .../commons/core/domain/v4/ODataObjectFactoryImpl.java | 1 - 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java index 853a1b750..95a1e9f9b 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java @@ -119,9 +119,9 @@ public class OpenTypeTestITCase extends AbstractTestITCase { assertEquals(String.class, rowIndex.getAdditionalProperty("aString").getClass()); assertEquals(Boolean.class, rowIndex.getAdditionalProperty("aBoolean").getClass()); assertEquals(Double.class, rowIndex.getAdditionalProperty("aDouble").getClass()); -// assertEquals(Short.class, rowIndex.getAdditionalProperty("aByte").getClass()); // trova integer -// assertEquals(Byte.MAX_VALUE, rowIndex.getAdditionalProperty("aByte")); -// assertEquals(Calendar.class, rowIndex.getAdditionalProperty("aDate").getClass()); // trova stringa + assertEquals(Byte.class, rowIndex.getAdditionalProperty("aByte").getClass()); + assertEquals(Byte.MAX_VALUE, rowIndex.getAdditionalProperty("aByte")); + assertTrue(Calendar.class.isAssignableFrom(rowIndex.getAdditionalProperty("aDate").getClass())); // assertEquals(ContactDetails.class, rowIndex.getAdditionalProperty("aContact").getClass().getInterfaces()[0]); entityContext.detachAll(); diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java index 9b0ce9dc5..25b50655d 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java @@ -157,8 +157,12 @@ public class OpenTypeTestITCase extends AbstractTestITCase { rowIndex.getProperty("aBoolean").getPrimitiveValue().getTypeKind()); assertTrue(rowIndex.getProperty("aDouble").hasPrimitiveValue()); assertTrue(rowIndex.getProperty("aByte").hasPrimitiveValue()); + assertEquals(EdmPrimitiveTypeKind.SByte, rowIndex.getProperty("aByte").getPrimitiveValue().getTypeKind()); assertTrue(rowIndex.getProperty("aDate").hasPrimitiveValue()); + assertEquals(EdmPrimitiveTypeKind.DateTime, rowIndex.getProperty("aDate").getPrimitiveValue().getTypeKind()); assertTrue(rowIndex.getProperty("aContact").hasComplexValue()); + assertEquals("Microsoft.Test.OData.Services.OpenTypesService.ContactDetails", + rowIndex.getProperty("aContact").getValue().getTypeName()); assertTrue(rowIndex.getProperty("aContact").getComplexValue().get("SignedByte").hasPrimitiveValue()); final ODataDeleteResponse deleteRes = getClient().getCUDRequestFactory(). diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java index b2540dad3..4c7f4b78d 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java @@ -132,7 +132,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase { newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Blue"))); product.getProperties().add(getClient().getObjectFactory().newCollectionProperty("CoverColors", getClient().getObjectFactory(). - newCollectionValue("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail"))); + newCollectionValue("Microsoft.Test.OData.Services.ODataWCFService.Color"))); product.getProperty("CoverColors").getCollectionValue().add(getClient().getObjectFactory(). newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Green")); product.getProperty("CoverColors").getCollectionValue().add(getClient().getObjectFactory(). diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java index bb115cfca..716d9b319 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java @@ -209,7 +209,7 @@ abstract class AbstractJsonSerializer extends ODataJacksonSerializer { } protected void valuable(final JsonGenerator jgen, final Valuable valuable, final String name) throws IOException { - if (serverMode && !Constants.VALUE.equals(name) && !(valuable instanceof Annotation)) { + if (!Constants.VALUE.equals(name) && !(valuable instanceof Annotation) && !valuable.getValue().isComplex()) { String type = valuable.getType(); if (StringUtils.isBlank(type) && valuable.getValue().isPrimitive() || valuable.getValue().isNull()) { type = EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java index b8ae8d3fa..cce924151 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java @@ -47,7 +47,7 @@ public abstract class AbstractODataCollectionValue * @param typeName type name. */ public AbstractODataCollectionValue(final String typeName) { - super(typeName); + super(typeName == null || typeName.startsWith("Collection(") ? typeName : "Collection(" + typeName + ")"); } protected abstract ODataCollectionValue getThis(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataObjectFactoryImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataObjectFactoryImpl.java index 8ebdaebc7..a89682ebd 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataObjectFactoryImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataObjectFactoryImpl.java @@ -153,5 +153,4 @@ public class ODataObjectFactoryImpl extends AbstractODataObjectFactory implement public ODataDelta newDelta(final URI next) { return new ODataDeltaImpl(next); } - }