Why do I get a MismatchedInputException when taking value of bodyAsString ?

1
0
-1

I'm calling a REST service using GET method which returns a single value, say : 99.

As this is not a valid json object I use the bodyAsString property but I get an exception :

org.bonitasoft.engine.connector.ConnectorException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `java.util.HashMap` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('99')

I don't understand why Bonita is trying to deserialize it into a HashMap when I request a String ?

Comments

Submitted by cjundt_1868075 on Tue, 06/02/2020 - 11:05

You're right, the web service is returning a json content-type header despite returned value is not valid json.

Thank you for the hint !

1 answer

1
0
-1
This one is the BEST answer!

Did you check if the request response doesn't have a Json content-type ? If it has a content-type header with application/json then the connector will try to interpret the response as a json object and failed if the response body is not json.

Comments

Submitted by cjundt_1868075 on Tue, 06/02/2020 - 16:08

Still, I think there is a bug in the connector :

  1. Response body "abc" for instance is a valid json value and should be interpreted as a String (same for dates, numbers, boolean values...).
  2. Even in case of a malformed json expression, when using bodyAsString as a workaround the connector should not try to interpret the response as a json object even if the response has a json content-type.
Submitted by romain.bioteau on Tue, 06/02/2020 - 16:49

It is possible to be more permissive and have a fallback behavior, feel free to contribute a pull request here

Notifications