[java][microprofile] Support useOneOfInterfaces with JSON-B serialization (stacked on #24190)#24197
Draft
Ignacio-Vidal wants to merge 2 commits into
Draft
Conversation
Route oneOf schemas to the shared oneof_interface template in the microprofile library's model.mustache, so useOneOfInterfaces=true renders a oneOf schema as a Java interface implemented by its subtypes, instead of an unrelated pojo. The microprofile library ships its own model.mustache (it overrides the base to support JSON-B and the jakarta/javax package split), which did not carry the oneOf-interface routing the base template has. Adding the routing lets the existing global oneof_interface template render the interface; children already implement it via x-implements. Scoped to serializationLibrary=jackson (the interface polymorphism annotations are Jackson-based). Adds a self-consistent oneof_interface_petstore.yaml fixture, a JavaClientCodegenTest case, and a microprofile-oneof-interface sample.
…tion Add JSON-B coverage for the useOneOfInterfaces feature in the microprofile library. With serializationLibrary=jsonb and microprofileRestClientVersion=3.0, the generated oneOf interface carries JSON-B polymorphism (@JsonbTypeInfo / @JsonbSubtype) instead of the Jackson annotations, driven by the existing jsonbPolymorphism path in typeInfoAnnotation.mustache. No generator source change is required - this locks the behaviour in with a sample and a test. - new JavaClientCodegenTest#oneOfInterfaceMicroprofileJsonb asserting the interface emits @JsonbTypeInfo(key="petType") + @JsonbSubtype CAT/DOG and no Jackson annotations, and that children implement the interface. - new bin/configs/java-microprofile-oneof-interface-jsonb.yaml + generated microprofile-oneof-interface-jsonb sample (JSON-B, restClientVersion 3.0). - register the sample in the samples-java-client-jdk11 workflow so CI compiles it.
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.
Stacked on #24190
This PR is stacked on top of #24190 (
[java][microprofile] Support useOneOfInterfaces). It adds JSON-B coverage for the same feature. Review/merge #24190 first — until it merges, this PR's diff transiently includes that commit.What & why
#24190renders aoneOfschema as an interface in the microprofile library and its committed sample usesserializationLibrary=jackson. The microprofile library also supports JSON-B, and the sharedtypeInfoAnnotation.mustachealready has ajsonbPolymorphismbranch that emits@JsonbTypeInfo/@JsonbSubtype. That path is enabled forserializationLibrary=jsonb+microprofileRestClientVersion=3.0(JavaClientCodegensetsjsonbPolymorphism).So
useOneOfInterfaces+ JSON-B already works — this PR locks it in with a sample and a test. No generator source change is required.Generated interface under JSON-B (from the committed sample):
No Jackson annotations are emitted; children
implements PetRequest.Changes
JavaClientCodegenTest#oneOfInterfaceMicroprofileJsonb— asserts the interface emits@JsonbTypeInfo(key = "petType")+ theCAT/DOG@JsonbSubtypemappings, emits no@JsonTypeInfo/@JsonSubTypes, and that children implement the interface.bin/configs/java-microprofile-oneof-interface-jsonb.yaml→samples/client/petstore/java/microprofile-oneof-interface-jsonb(JSON-B, restClientVersion 3.0). Reuses the sameoneof_interface_petstore.yamlfixture as the jackson sample.samples-java-client-jdk11.yamlso it is compiled on every run (the jackson sample from [java][microprofile] Extend support for useOneOfInterfaces to the microprofile library when Jackson serialisation is enabled #24190 is not currently in a matrix; this one is).Verification
JavaClientCodegenTest#oneOfInterfaceMicroprofileJsonbpasses.java.version=11target (@Jsonb*annotations resolve againstjakarta.json.bind-api3.0.0).Scope / caveat
The
jsonbPolymorphismflag is set only formicroprofileRestClientVersion=3.0. For older rest-client versions (1.4.1/2.0), a JSON-B oneOf interface is still emitted but without discriminator annotations — that pre-existing gate is unchanged and out of scope here.Summary by cubic
Adds JSON-B support and test coverage for
useOneOfInterfacesin the Java MicroProfile client. WhenserializationLibrary=jsonbandmicroprofileRestClientVersion=3.0, the generated oneOf interface uses JSON-B polymorphism, with a new sample compiled in CI.@JsonbTypeInfo(key="petType")and@JsonbSubtypemappings; no Jackson annotations; children implement the interface (tested byoneOfInterfaceMicroprofileJsonb).bin/configs/java-microprofile-oneof-interface-jsonb.yamland thesamples/client/petstore/java/microprofile-oneof-interface-jsonbproject; registered in.github/workflows/samples-java-client-jdk11.yaml.Written for commit 48343d5. Summary will update on new commits.