fix: recognize @XmlJavaTypeAdapter in JaxbConverterFactory#4702
Open
amitmishra11 wants to merge 1 commit into
Open
fix: recognize @XmlJavaTypeAdapter in JaxbConverterFactory#4702amitmishra11 wants to merge 1 commit into
amitmishra11 wants to merge 1 commit into
Conversation
…axb and jaxb3 JaxbConverterFactory only checked for @XmlRootElement when deciding whether to create a converter for a given type. Classes that are annotated with @XmlJavaTypeAdapter (the JAXB pattern for immutable or no-arg-constructor-free types) were not recognised, causing the factory to return null and Retrofit to skip JAXB entirely for those types. Add an isJaxbAnnotated() helper that accepts a class if it carries either @XmlRootElement or @XmlJavaTypeAdapter, and update both the javax.xml.bind (jaxb) and jakarta.xml.bind (jaxb3) factories to use it. Also add ImmutablePoint as a test fixture and two new tests to confirm that the factory returns a non-null converter for a type bearing only @XmlJavaTypeAdapter. Fixes lysine-dev#3349
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3349
JaxbConverterFactoryonly checked for@XmlRootElementwhen decidingwhether to return a converter for a given type. Classes annotated with
@XmlJavaTypeAdapter(the standard JAXB pattern for handling immutabletypes or types without a no-arg constructor) were not recognised, so the
factory returned
nulland Retrofit fell through to subsequent converterfactories or produced a misleading error.
The fix is minimal: extract an
isJaxbAnnotated()predicate thataccepts a class if it carries either
@XmlRootElementor@XmlJavaTypeAdapter, and call it from bothrequestBodyConverterandresponseBodyConverter. The same change is applied to thejaxb3(jakarta namespace) variant.
Changes
retrofit-converters/jaxb/src/main/java/.../JaxbConverterFactory.javaXmlJavaTypeAdapterisJaxbAnnotated()helperrequestBodyConverterandresponseBodyConverterretrofit-converters/jaxb3/src/main/java/.../JaxbConverterFactory.javajakarta.xml.bindimportsretrofit-converters/jaxb/src/test/java/.../ImmutablePoint.java(new)@XmlJavaTypeAdapterand no@XmlRootElementretrofit-converters/jaxb/src/test/java/.../JaxbConverterFactoryTest.javaImmutablePointTesting
./gradlew :retrofit-converters:jaxb:testpasses (12 tests, 0 failures).