fix: let protobuf provider write protobuf DTOs to JSON - #712
Merged
Conversation
ProtobufJsonProvider and Jersey's auto-registered DefaultJacksonJaxbJsonProvider both declare MessageBodyWriter<Object> for application/json, so Jersey's WorkerComparator ties on type distance, media type distance and the custom flag alike, and the winner is whichever comes first in an unordered provider set. Agate happened to sort the protobuf provider first, but the order shifts with the set of scanned classes; when Jackson wins, writing any protobuf DTO fails with "Direct self-reference leading to cycle" on UnknownFieldSet, as it did in Mica. Register AgateJacksonJsonProvider instead, a DefaultJacksonJaxbJsonProvider that declines protobuf messages and collections of them, so the choice no longer depends on provider order. JacksonFeature's own provider is opted out via InternalProperties.JSON_FEATURE; its two exception mappers are registered explicitly to keep the previous behaviour on malformed JSON. The explicit ProtobufJsonProvider/ProtobufNativeProvider registrations are dropped: package scanning already finds them, and being registered does not make them win the tie the previous comment described.
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.
ProtobufJsonProvider and Jersey's auto-registered
DefaultJacksonJaxbJsonProvider both declare MessageBodyWriter for application/json, so Jersey's WorkerComparator ties on type distance, media type distance and the custom flag alike, and the winner is whichever comes first in an unordered provider set. Agate happened to sort the protobuf provider first, but the order shifts with the set of scanned classes; when Jackson wins, writing any protobuf DTO fails with "Direct self-reference leading to cycle" on UnknownFieldSet, as it did in Mica.
Register AgateJacksonJsonProvider instead, a DefaultJacksonJaxbJsonProvider that declines protobuf messages and collections of them, so the choice no longer depends on provider order. JacksonFeature's own provider is opted out via InternalProperties.JSON_FEATURE; its two exception mappers are registered explicitly to keep the previous behaviour on malformed JSON.
The explicit ProtobufJsonProvider/ProtobufNativeProvider registrations are dropped: package scanning already finds them, and being registered does not make them win the tie the previous comment described.