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

Ability to disable tokenization on jsonpath split returning a single element as string

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.4.0
    • 3.7.0
    • camel-core
    • None
    • Unknown

    Description

      Sample json message body:

      { "text": \{ "div": "some, text" }

       }

      DSL

      .split(jsonpath("text.div"))

      Result

      The "some, text" string gets split into two pieces: "some" and " text"; (it's split on the comma token).

      I do not want the above string to be split on comma tokens, but this appears to happen by default when jsonpath returns a single element as a string value. A workaround is to override the default tokenization by providing some string I hope never appears in the json I process. For example:
      .split(jsonpath("text.div").tokenize("@@@"))

      If I alter the json as follows, CamelSplitSize is 1 and the output is "some, text" (no split on comma):

      { "text": \{ "div": [ "some, text" ] }

       } 

      I discussed this with Claus on Zulip and this was his response:
      "Yeah its a bit of corner case, and as you say you can change the token to @@@ or something. To avoid introducing a new option for a case like this, then we can look at if you specify token="false" then its turned off. You are welcome to create a Jira"

      Only concern with the following is if someone actually wanted to tokenize a string on "false" rather than disable tokenization. Possible I misinterpreted Claus' suggestion though.

      .split(jsonpath("text.div").tokenize("false"))

      I'd be happy to work on contributing this capability to camel and/or unit test cases to help facilitate a contribution.

      Thanks in advance

      Attachments

        Activity

          People

            Unassigned Unassigned
            scarrier Scott Carrier
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: