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

Allow DataFormats to unmarshal known data formats without first converting to bytes

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.0
    • 4.4.0
    • camel-core
    • None
    • Unknown

    Description

      The motivating example here is unmarshalling JAXB from a String message body, but the issue exists for other data formats as well, e.g. JSON. In a route like

      from("direct:receive-a-string")
      .unmarshal().jaxb()

      Camel will unnecessarily serialize the String to bytes, then deserialize the bytes to JAXB Java objects. In addition to being inefficient, this can cause encoding issues if the encoding used by Camel to serialize the String doesn't match the encoding set in the XML declaration.

      The reason Camel needs to serialize to bytes is that the DataFormat interface takes an InputStream parameter in the unmarshal method. Because of this parameter, the UnmarshalProcessor needs to convert the message body to bytes before calling the data format.

      We should be able to introduce a new method with the signature unmarshal(Exchange), which would let data formats examine the body's type, and decide whether it is necessary to serialize to bytes before unmarshalling. For instance, the JAXB data format could choose only to serialize to bytes if the input body is not one of the types accepted by the JAXB Unmarshaller, or a String.

      We should be able to implement this in a backwards compatible way, by introducing the new method as a default method on the DataFormat interface. The default implementation should extract the exchange message body as an InputStream, and call the existing unmarshal method. We can then update UnmarshalProcessor to only call the new method.

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              srdo Stig Rohde Døssing
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: