Lars Rothberg-Hansen created CAMEL-8303:
-------------------------------------------
Summary: InvalidPayloadException when storing a String using
camel-couchdb
Key: CAMEL-8303
URL: https://issues.apache.org/jira/browse/CAMEL-8303
Project: Camel
Issue Type: Bug
Components: camel-couchdb
Reporter: Lars Rothberg-Hansen
Priority: Minor
According to the documentation, it should be possible to send through an
Exchange with the body containing a String
"If the body is an instance of String, then it will be marshalled into a GSON
object before insert."
When doing this, an InvalidPayloadException occurs.
The culprit is this line in the CouchDbProducer:
"return new Gson().toJsonTree(body)"
According to the Gson documentation, this should not be executed on Generic
types as the String will not be parsed, but stored in a JsonPrimitive as
opposed to the expected JsonObject.
In order to correct it, is to use the code which parses the String (Sorry,
don't have time just now to do a proper patch):
try{
return new JsonParser().parse((String)body);
}catch(JsonSyntaxException jse){
throw new InvalidPayloadException(exchange, body != null ? body.getClass() :
null);
}
It's also worth mentioning that existing test cases does not result in this
Exception and the original 2.14.1 code base as long as my local modified
version both passes the tests.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)