From 87fa79ad933dd85ae875a19e5b3171101e0585fe Mon Sep 17 00:00:00 2001 From: Christian Amend Date: Mon, 27 Apr 2015 14:48:56 +0200 Subject: [PATCH] [OLINGO-604] Ignore odata annotations for action requests --- .../deserializer/json/ODataJsonDeserializer.java | 16 ++++++++++++++++ ...DataJsonDeserializerActionParametersTest.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java index 66da3fcfa..a6c3e8d15 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java @@ -195,6 +195,22 @@ public class ODataJsonDeserializer implements ODataDeserializer { Map parameters = new LinkedHashMap(); if (tree != null) { consumeParameters(edmAction, tree, parameters); + + final List toRemove = new ArrayList(); + Iterator> fieldsIterator = tree.fields(); + while (fieldsIterator.hasNext()) { + Map.Entry field = fieldsIterator.next(); + + if (field.getKey().contains(ODATA_CONTROL_INFORMATION_PREFIX)) { + // Control Information is ignored for requests as per specification chapter "4.5 Control Information" + toRemove.add(field.getKey()); + } else if (field.getKey().contains(ODATA_ANNOTATION_MARKER)) { + throw new DeserializerException("Custom annotation with field name: " + field.getKey() + " not supported", + DeserializerException.MessageKeys.NOT_IMPLEMENTED); + } + } + // remove here to avoid iterator issues. + tree.remove(toRemove); assertJsonNodeIsEmpty(tree); } return DeserializerResultImpl.with().actionParameters(parameters).build(); diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java index 01166a220..9df2b3405 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java @@ -65,6 +65,22 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese assertTrue(parameters.isEmpty()); } + @Test + public void ignoreODataAnnotations() throws Exception { + final String input = + "{\"ParameterDuration@odata.type\":\"Edm.Duration\"," + + "\"ParameterDuration\":\"P42DT11H22M33S\",\"ParameterInt16\":42}"; + final Map parameters = deserialize(input, "UARTTwoParam"); + assertNotNull(parameters); + assertEquals(2, parameters.size()); + Parameter parameter = parameters.get("ParameterInt16"); + assertNotNull(parameter); + assertEquals((short) 42, parameter.getValue()); + parameter = parameters.get("ParameterDuration"); + assertNotNull(parameter); + assertEquals(BigDecimal.valueOf(3669753), parameter.getValue()); + } + @Test(expected = DeserializerException.class) public void bindingParameter() throws Exception { deserialize("{\"ParameterETAllPrim\":{\"PropertyInt16\":42}}", "BAETAllPrimRT", "ETAllPrim");