camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-8303: Storing a string in couchdb should parse it to json properly. Thanks to Lars Rothberg-Hansen for the patch.
Date Sun, 15 Feb 2015 17:07:36 GMT
CAMEL-8303: Storing a string in couchdb should parse it to json properly. Thanks to Lars Rothberg-Hansen
for the patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cc21a31d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cc21a31d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cc21a31d

Branch: refs/heads/camel-2.14.x
Commit: cc21a31dc09c426599e485b32abd5eb34fca0623
Parents: 725e53c
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Feb 15 18:07:45 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Feb 15 18:08:10 2015 +0100

----------------------------------------------------------------------
 .../org/apache/camel/component/couchdb/CouchDbProducer.java | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cc21a31d/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbProducer.java
b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbProducer.java
index 97ad41b..5ae5cef 100644
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbProducer.java
+++ b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/CouchDbProducer.java
@@ -16,9 +16,10 @@
  */
 package org.apache.camel.component.couchdb;
 
-import com.google.gson.Gson;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.impl.DefaultProducer;
@@ -51,7 +52,11 @@ public class CouchDbProducer extends DefaultProducer {
     JsonElement getBodyAsJsonElement(Exchange exchange) throws InvalidPayloadException {
         Object body = exchange.getIn().getMandatoryBody();
         if (body instanceof String) {
-            return new Gson().toJsonTree(body);
+            try {
+                return new JsonParser().parse((String) body);
+            } catch (JsonSyntaxException jse) {
+                throw new InvalidPayloadException(exchange, body.getClass());
+            }
         } else if (body instanceof JsonElement) {
             return (JsonElement) body;
         } else {


Mime
View raw message