diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java index 6242975aa..e85d7bad6 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java @@ -275,6 +275,11 @@ public abstract class ServiceRequest { SerializerException { return this.odata.createSerializer(getResponseContentType()); } + + public ODataSerializer getSerializer(ContentType type) throws ContentNegotiatorException, + SerializerException { + return this.odata.createSerializer(type); + } public Map getPreferences(){ HashMap map = new HashMap(); diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java index f9c35baf5..290abb5fc 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java @@ -51,17 +51,24 @@ public class PropertyResponse extends ServiceResponse { public static PropertyResponse getInstance(ServiceRequest request, ODataResponse response, EdmType edmType, ContextURL contextURL, boolean collection) throws ContentNegotiatorException, SerializerException { + + ContentType type = request.getResponseContentType(); + ODataSerializer serializer = null; + if (type.equals(ContentType.TEXT_PLAIN)) { + serializer = request.getSerializer(ContentType.APPLICATION_JSON); + } else { + serializer = request.getSerializer(); + } + if (edmType.getKind() == EdmTypeKind.PRIMITIVE) { PrimitiveSerializerOptions options = request.getSerializerOptions( - PrimitiveSerializerOptions.class, contextURL, false); - ContentType type = request.getResponseContentType(); - return new PropertyResponse(request.getServiceMetaData(), request.getSerializer(), response, + PrimitiveSerializerOptions.class, contextURL, false); + return new PropertyResponse(request.getServiceMetaData(), serializer, response, options, type, collection, request.getPreferences()); } ComplexSerializerOptions options = request.getSerializerOptions(ComplexSerializerOptions.class, - contextURL, false); - ContentType type = request.getResponseContentType(); - return new PropertyResponse(request.getServiceMetaData(), request.getSerializer(), response, + contextURL, false); + return new PropertyResponse(request.getServiceMetaData(), serializer, response, options, type, collection, request.getPreferences()); } diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java index 8bb4d5ab5..048643940 100644 --- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java +++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java @@ -203,7 +203,18 @@ public class TripPinServiceTest { HttpResponse response = httpGET(baseURL + "/Airlines('AA')/Name/$value", 200); assertEquals("American Airlines", IOUtils.toString(response.getEntity().getContent())); } - + + @Test + public void testUpdateRawValue() throws Exception { + // Note that in-real services must convert raw value (byte[]) to + // the data type it needs to save in in updateProperty method + String editUrl = baseURL + "/Airlines('AF')/Name/$value"; + HttpPut request = new HttpPut(editUrl); + request.setEntity(new StringEntity("Safari")); + HttpResponse response = httpSend(request, 204); + EntityUtils.consumeQuietly(response.getEntity()); + } + @Test @Ignore // TODO: Support geometry types to make this run public void testReadComplexProperty() throws Exception {