diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ClientPrimitiveValueImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ClientPrimitiveValueImpl.java index 4824632bdb..a8590a73c6 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ClientPrimitiveValueImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ClientPrimitiveValueImpl.java @@ -56,7 +56,8 @@ public BuilderImpl setType(final EdmType type) { @Override public BuilderImpl setType(final EdmPrimitiveTypeKind type) { - if (type == EdmPrimitiveTypeKind.Stream) { + // Ilya: throwing these exceptions from here doesn't make sense + /*if (type == EdmPrimitiveTypeKind.Stream) { throw new IllegalArgumentException(String.format( "Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString())); } @@ -66,7 +67,7 @@ public BuilderImpl setType(final EdmPrimitiveTypeKind type) { + "An entity can declare a property to be of type Geometry. " + "An instance of an entity MUST NOT have a value of type Geometry. " + "Each value MUST be of some subtype."); - } + }*/ instance.typeKind = type == null ? EdmPrimitiveTypeKind.String : type; instance.type = EdmPrimitiveTypeFactory.getInstance(instance.typeKind); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonODataErrorDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonODataErrorDeserializer.java index 2584db9abc..9a0e9ecf96 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonODataErrorDeserializer.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/JsonODataErrorDeserializer.java @@ -34,54 +34,91 @@ public class JsonODataErrorDeserializer extends JsonDeserializer { - public JsonODataErrorDeserializer(final boolean serverMode) { - super(serverMode); - } + public JsonODataErrorDeserializer(final boolean serverMode) { + super(serverMode); + } - protected ODataError doDeserialize(final JsonParser parser) throws IOException { + protected ODataError doDeserialize(final JsonParser parser) throws IOException { - final ODataError error = new ODataError(); + final ODataError error = new ODataError(); - final ObjectNode tree = parser.getCodec().readTree(parser); - if (tree.has(Constants.JSON_ERROR)) { - final JsonNode errorNode = tree.get(Constants.JSON_ERROR); + final ObjectNode tree = parser.getCodec().readTree(parser); + if (tree.has(Constants.JSON_ERROR)) { + final JsonNode errorNode = tree.get(Constants.JSON_ERROR); - if (errorNode.has(Constants.ERROR_CODE)) { - error.setCode(errorNode.get(Constants.ERROR_CODE).textValue()); - } - if (errorNode.has(Constants.ERROR_MESSAGE)) { - final JsonNode message = errorNode.get(Constants.ERROR_MESSAGE); - if (message.isValueNode()) { - error.setMessage(message.textValue()); - } else if (message.isObject()) { - error.setMessage(message.get(Constants.VALUE).asText()); - } - } - if (errorNode.has(Constants.ERROR_TARGET)) { - error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue()); - } - if (errorNode.hasNonNull(Constants.ERROR_DETAILS)) { - List details = new ArrayList<>(); - JsonODataErrorDetailDeserializer detailDeserializer = new JsonODataErrorDetailDeserializer(serverMode); - for (JsonNode jsonNode : errorNode.get(Constants.ERROR_DETAILS)) { - details.add(detailDeserializer.doDeserialize(jsonNode.traverse(parser.getCodec())) - .getPayload()); - } + if (errorNode.has(Constants.ERROR_CODE)) { + error.setCode(errorNode.get(Constants.ERROR_CODE).textValue()); + } + if (errorNode.has(Constants.ERROR_MESSAGE)) { + final JsonNode message = errorNode.get(Constants.ERROR_MESSAGE); + if (message.isValueNode()) { + error.setMessage(message.textValue()); + } else if (message.isObject()) { + error.setMessage(message.get(Constants.VALUE).asText()); + } + } + if (errorNode.has(Constants.ERROR_TARGET)) { + error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue()); + } + if (errorNode.hasNonNull(Constants.ERROR_DETAILS)) { + List details = new ArrayList<>(); + JsonODataErrorDetailDeserializer detailDeserializer = + new JsonODataErrorDetailDeserializer(serverMode); + for (JsonNode jsonNode : errorNode.get(Constants.ERROR_DETAILS)) { + details.add(detailDeserializer.doDeserialize( + jsonNode.traverse(parser.getCodec())).getPayload()); + } - error.setDetails(details); - } - if (errorNode.hasNonNull(Constants.ERROR_INNERERROR)) { - HashMap innerErrorMap = new HashMap<>(); - final JsonNode innerError = errorNode.get(Constants.ERROR_INNERERROR); - for (final Iterator itor = innerError.fieldNames(); itor.hasNext();) { - final String keyTmp = itor.next(); - final String val = innerError.get(keyTmp).toString(); - innerErrorMap.put(keyTmp, val); - } - error.setInnerError(innerErrorMap); - } - } + error.setDetails(details); + } + if (errorNode.hasNonNull(Constants.ERROR_INNERERROR)) { + HashMap innerErrorMap = new HashMap<>(); + final JsonNode innerError = errorNode.get(Constants.ERROR_INNERERROR); + for (final Iterator itor = innerError.fieldNames(); itor.hasNext();) { + final String keyTmp = itor.next(); + final String val = innerError.get(keyTmp).toString(); + innerErrorMap.put(keyTmp, val); + } + error.setInnerError(innerErrorMap); + } + } else if (tree.has(Constants.ERROR_CODE)) { + if (tree.has(Constants.ERROR_CODE)) { + error.setCode(tree.get(Constants.ERROR_CODE).textValue()); + } + if (tree.has(Constants.ERROR_MESSAGE)) { + final JsonNode message = tree.get(Constants.ERROR_MESSAGE); + if (message.isValueNode()) { + error.setMessage(message.textValue()); + } else if (message.isObject()) { + error.setMessage(message.get(Constants.VALUE).asText()); + } + } + if (tree.has(Constants.ERROR_TARGET)) { + error.setTarget(tree.get(Constants.ERROR_TARGET).textValue()); + } + if (tree.hasNonNull(Constants.ERROR_DETAILS)) { + List details = new ArrayList<>(); + JsonODataErrorDetailDeserializer detailDeserializer = + new JsonODataErrorDetailDeserializer(serverMode); + for (JsonNode jsonNode : tree.get(Constants.ERROR_DETAILS)) { + details.add(detailDeserializer.doDeserialize( + jsonNode.traverse(parser.getCodec())).getPayload()); + } - return error; - } + error.setDetails(details); + } + if (tree.hasNonNull(Constants.ERROR_INNERERROR)) { + HashMap innerErrorMap = new HashMap<>(); + final JsonNode innerError = tree.get(Constants.ERROR_INNERERROR); + for (final Iterator itor = innerError.fieldNames(); itor.hasNext();) { + final String keyTmp = itor.next(); + final String val = innerError.get(keyTmp).toString(); + innerErrorMap.put(keyTmp, val); + } + error.setInnerError(innerErrorMap); + } + } + + return error; + } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java index dfd3d41a0e..ce3d0a709b 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java @@ -851,8 +851,9 @@ protected ClientValue getODataValue(FullQualifiedName type, value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag)); } } else if (valuable.isEnum()) { + Object enumValue = valuable.asEnum(); value = client.getObjectFactory().newEnumValue(type == null ? null : type.toString(), - valuable.asEnum().toString()); + enumValue==null? null: enumValue.toString()); } else if (valuable.isComplex()) { final ClientComplexValue lcValue = client.getObjectFactory().newComplexValue(type == null ? null : type.toString()); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java index bc08918e69..e61251ebc4 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java @@ -363,7 +363,7 @@ private void annotated(final ContentType contentType) throws EdmPrimitiveTypeExc assertEquals("com.contoso.display.styleType", annotation.getValue().getTypeName()); assertTrue(annotation.hasComplexValue()); assertEquals(2, - annotation.getValue().asComplex().get("order").getPrimitiveValue().toCastValue(Integer.class), 0); + annotation.getValue().asComplex().get("order").getPrimitiveValue().toCastValue(Integer.class).intValue(), 0); final ClientEntity written = client.getBinder().getODataEntity( new ResWrap((URI) null, null, client.getBinder().getEntity(entity))); diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmAnnotation.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmAnnotation.java index 7ebeeee4de..3487790449 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmAnnotation.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmAnnotation.java @@ -25,6 +25,8 @@ */ public interface EdmAnnotation extends EdmAnnotatable { + String getTermAsString(); + /** * @return the term of this annotation */ diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationImpl.java index c4ab9107e5..b44ed3ee39 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationImpl.java @@ -38,6 +38,11 @@ public EdmAnnotationImpl(final Edm edm, final CsdlAnnotation annotation) { this.annotation = annotation; } + @Override + public String getTermAsString() { + return annotation.getTerm(); + } + @Override public EdmTerm getTerm() { if (term == null) { 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 f886c84089..2d38b2949e 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 @@ -128,6 +128,9 @@ private EdmTypeInfo(final Edm edm, final String typeExpression, final boolean in } } } + if (primitiveType==null && typeDefinition==null && enumType==null && complexType==null && entityType==null) { + primitiveType = EdmPrimitiveTypeKind.String; + } } public String internal() { diff --git a/lib/server-tecsvc/pom.xml b/lib/server-tecsvc/pom.xml index 8955382298..4036bea0fc 100644 --- a/lib/server-tecsvc/pom.xml +++ b/lib/server-tecsvc/pom.xml @@ -97,7 +97,7 @@ - +