Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-8303

InvalidPayloadException when storing a String using camel-couchdb

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.14.2, 2.15.0
    • camel-couchdb
    • None
    • Unknown

    Description

      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.

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            larhan Lars Rothberg-Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: