oscerd opened a new pull request, #28156:
URL: https://github.com/apache/camel/pull/28156

   The Jackson data formats only read their `CamelJacksonUnmarshalType` header 
when `allowUnmarshallType` is enabled.
   The Gson and JSON-B data formats honoured their equivalent header 
unconditionally: `GsonDataFormat.unmarshal()` and
   `JsonbDataFormat.unmarshal()` resolved the class named by 
`CamelGsonUnmarshalType` / `CamelJsonbUnmarshallType` with
   the class resolver and unmarshalled into it.
   
   This PR gives both data formats the `allowUnmarshallType` option, with the 
same name, semantics and default (`false`)
   as Jackson:
   
   - `GsonDataFormat` / `JsonbDataFormat`: new `allowUnmarshallType` property 
(in `includeProperties`, so it is in the
     `gson` / `jsonb` metadata); the header is read only when it is enabled. 
`JsonbDataFormat.UNMARSHAL_TYPE` names the
     header that was a string literal.
   - `JsonDataFormatReifier`: passes `allowUnmarshallType` for `library=Gson` 
and `library=Jsonb` too, so
     `<json library="Gson" allowUnmarshallType="true"/>` and `new 
JsonDataFormat(JsonLibrary.Gson).allowUnmarshallType(true)`
     work; the model description of the option mentions the three headers.
   - Upgrade guide note for 4.24: a route that sets the header must enable the 
option.
   
   **camel-jaxb is not changed**, unlike what the Jira suggests: the JAXB data 
format unmarshals with
   `Unmarshaller.unmarshal(reader, partClass)`, and JAXB only accepts a class 
known to the `JAXBContext` of the data
   format, so the `CamelJaxbPartClass` header cannot select another class 
(checked: a class outside the context is refused
   with `JAXBException: ... is not known to this context`, and is never 
instantiated). Gating it would break the documented
   partial unmarshalling override for no gain. camel-fastjson has no such 
header.
   
   ### Tests
   - `GsonUnmarshalTypeFromHeaderTest`: the header is used with 
`allowUnmarshallType(true)` and ignored by default (a `Map`
     is returned); `SpringGsonUnmarshalTypeFromHeaderTest` now sets 
`allowUnmarshallType="true"`, which also covers the
     reifier and the XML DSL.
   - `JsonbUnmarshalTypeFromHeaderTest`: the same for JSON-B.
   - `GsonDataFormatTest` no longer stubs `exchange.getIn()`: the data format 
does not read the exchange any more when the
     option is off (strict Mockito flagged the unused stub).
   - `camel-gson`: 28 tests, `camel-jsonb`: 18 tests, 0 failures. With the 
previous data formats, the default case returns
     the class named by the header (`TestPojo`) instead of a `Map`.
   - Full reactor `mvn clean install -DskipTests -DskipITs`: 706/706, only the 
expected regenerated files (the new option
     in the `gson` / `jsonb` metadata and configurers; the option description 
in the model, the Jackson metadata, the XML
     schemas and the YAML DSL).
   
   JIRA: https://issues.apache.org/jira/browse/CAMEL-24426
   
   _Claude Code on behalf of Andrea Cosentino (@oscerd)_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to