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

encoding problems in jsonpath

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.15.2
    • 2.16.0
    • camel-jsonpath
    • None
    • Patch Available
    • Unknown

    Description

      I detected three different encoding problems in jsonpath:

      • if jsonpath is called with an input stream which has an encoding different from the default encoding (given by Charset.defaultCharset()) then jsonpath still uses the default encoding. Error location in JsonPathEngine:
        else if (json instanceof InputStream) { InputStream is = (InputStream) json; return path.read(is, Charset.defaultCharset().displayName(), configuration);}
      • if jsonpath is called with a json file whose encoding is different from UTF-8, then jsonpath still parses the document with UTF-8. Error location in JsonPathEngine:
        else if (json instanceof File) { File file = (File) json; return path.read(file, configuration); }

        path.read(file, configuration) uses always UTF-8

      • if jsonpath is called with an URL pointing to a JSON document whose encoding is different from UTF-8, then jsonPath still parses the document with UTF-8. Error location in JsonPathEngine:
        else if (json instanceof URL) { URL url = (URL) json; return path.read(url, configuration); }

        path.read(url, configuration) uses UTF-8

      My solution proposal is to determine the encoding of the JSON documents automatically according to the specification RFC-4627 (https://www.ietf.org/rfc/rfc4627.txt; see chapter 3. Encoding) and then call the method path.read(jsonDocument,foundEncoding,configuration) with the found encoding. See attached patch.

      Actually I can commit the patch myself. However, I would like that somebody who is more familiar with jsonpath than I does review my patch.

      So please tell me if my patch can be accepted or not. I can then do the actual commit or I will discard the patch.

      Attachments

        1. 0001-jsonpath-automatic-charset-detection.patch
          35 kB
          Franz Forsthofer
        2. booksUTF16BE.json
          1 kB
          Franz Forsthofer
        3. booksUTF16LE.json
          1 kB
          Franz Forsthofer
        4. jsonUCS2BigEndianWithBOM.txt
          0.2 kB
          Franz Forsthofer
        5. jsonUCS2BigEndianWithoutBOM.txt
          0.2 kB
          Franz Forsthofer
        6. jsonUCS2LittleEndianWithBom.txt
          0.2 kB
          Franz Forsthofer
        7. jsonUCS2LittleEndianWithoutBOM.txt
          0.2 kB
          Franz Forsthofer
        8. jsonUTF32BEWithBOM.txt
          0.5 kB
          Franz Forsthofer
        9. jsonUTF32BEWithoutBOM.txt
          0.5 kB
          Franz Forsthofer
        10. jsonUTF32LEWithBOM.txt
          0.5 kB
          Franz Forsthofer
        11. jsonUTF32LEWithoutBOM.txt
          0.5 kB
          Franz Forsthofer

        Activity

          People

            Unassigned Unassigned
            forsthofer Franz Forsthofer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: