[OLINGO-1446]Allow empty parameters for actions and action imports when there is no non binding parameter defined
This commit is contained in:
parent
a058f1c1cf
commit
ddaab6b0fa
|
@ -83,7 +83,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.server.core.deserializer.json;
|
package org.apache.olingo.server.core.deserializer.json;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
@ -32,6 +34,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
import org.apache.olingo.commons.api.Constants;
|
||||||
import org.apache.olingo.commons.api.IConstants;
|
import org.apache.olingo.commons.api.IConstants;
|
||||||
import org.apache.olingo.commons.api.constants.Constantsv00;
|
import org.apache.olingo.commons.api.constants.Constantsv00;
|
||||||
|
@ -304,14 +307,23 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
@Override
|
@Override
|
||||||
public DeserializerResult actionParameters(final InputStream stream, final EdmAction edmAction)
|
public DeserializerResult actionParameters(final InputStream stream, final EdmAction edmAction)
|
||||||
throws DeserializerException {
|
throws DeserializerException {
|
||||||
|
Map<String, Parameter> parameters = new HashMap<>();
|
||||||
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
byte[] inputContent = null;
|
||||||
try {
|
try {
|
||||||
ObjectNode tree = parseJsonTree(stream);
|
IOUtils.copy(stream, byteArrayOutputStream);
|
||||||
Map<String, Parameter> parameters = consumeParameters(edmAction, tree);
|
// copy the content of input stream to reuse it
|
||||||
|
inputContent = byteArrayOutputStream.toByteArray();
|
||||||
|
if (inputContent.length > 0) {
|
||||||
|
InputStream inputStream1 = new ByteArrayInputStream(inputContent);
|
||||||
|
ObjectNode tree = parseJsonTree(inputStream1);
|
||||||
|
parameters = consumeParameters(edmAction, tree);
|
||||||
|
|
||||||
if (tree.isObject()) {
|
if (tree.isObject()) {
|
||||||
removeAnnotations(tree);
|
removeAnnotations(tree);
|
||||||
}
|
}
|
||||||
assertJsonNodeIsEmpty(tree);
|
assertJsonNodeIsEmpty(tree);
|
||||||
|
}
|
||||||
return DeserializerResultImpl.with().actionParameters(parameters).build();
|
return DeserializerResultImpl.with().actionParameters(parameters).build();
|
||||||
|
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
|
|
|
@ -206,8 +206,10 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noContent() throws Exception {
|
public void noContent() throws Exception {
|
||||||
expectException("", "UARTTwoParam", null, MessageKeys.JSON_SYNTAX_EXCEPTION);
|
Map<String, Parameter> parameters = deserialize("", "UARTTwoParam", null);
|
||||||
expectException("", "BAETAllPrimRT", "ETAllPrim", MessageKeys.JSON_SYNTAX_EXCEPTION);
|
assertNotNull(parameters);
|
||||||
|
parameters = deserialize("", "BAETAllPrimRT", "ETAllPrim");
|
||||||
|
assertNotNull(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue