[java][microprofile] Support useOneOfInterfaces with JSON-B serialization (stacked on #24190)
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
#24190 renders a oneOf schema as an interface in the microprofile library and its committed sample uses serializationLibrary=jackson. The microprofile library also supports JSON-B, and the shared typeInfoAnnotation.mustache already has a jsonbPolymorphism branch that emits @JsonbTypeInfo / @JsonbSubtype. That path is enabled for serializationLibrary=jsonb + microprofileRestClientVersion=3.0 (JavaClientCodegen sets jsonbPolymorphism).
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):
@JsonbTypeInfo(key = "petType", value = {
@JsonbSubtype(alias = "CAT", type = CatRequest.class),
@JsonbSubtype(alias = "DOG", type = DogRequest.class),
})
public interface PetRequest {
public PetType getPetType();
}
No Jackson annotations are emitted; children implements PetRequest.
Changes
- Test
JavaClientCodegenTest#oneOfInterfaceMicroprofileJsonb— asserts the interface emits@JsonbTypeInfo(key = "petType")+ theCAT/DOG@JsonbSubtypemappings, emits no@JsonTypeInfo/@JsonSubTypes, and that children implement the interface. - Sample
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. - CI — registered the sample in
samples-java-client-jdk11.yamlso it is compiled on every run (the jackson sample from #24190 is not currently in a matrix; this one is).
Verification
JavaClientCodegenTest#oneOfInterfaceMicroprofileJsonbpasses.- The generated sample compiles under the sample's
java.version=11target (@Jsonb*annotations resolve againstjakarta.json.bind-api3.0.0).
Scope / caveat
The jsonbPolymorphism flag is set only for microprofileRestClientVersion=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 useOneOfInterfaces in the Java MicroProfile client. When serializationLibrary=jsonb and microprofileRestClientVersion=3.0, the generated oneOf interface uses JSON-B polymorphism, with a new sample compiled in CI.
- New Features
- Generates the oneOf interface with
@JsonbTypeInfo(key="petType")and@JsonbSubtypemappings; no Jackson annotations; children implement the interface (tested byoneOfInterfaceMicroprofileJsonb). - Adds
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. - Applies to MicroProfile Rest Client 3.0 only; older versions still generate the interface without JSON-B polymorphism.
- Generates the oneOf interface with