[java][microprofile] Support useOneOfInterfaces with JSON-B serialization (stacked on #24190)

Draft
IG
4mo ago
+3063-0

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") + the CAT/DOG @JsonbSubtype mappings, 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 same oneof_interface_petstore.yaml fixture as the jackson sample.
  • CI — registered the sample in samples-java-client-jdk11.yaml so it is compiled on every run (the jackson sample from #24190 is not currently in a matrix; this one is).

Verification

  • JavaClientCodegenTest#oneOfInterfaceMicroprofileJsonb passes.
  • The generated sample compiles under the sample's java.version=11 target (@Jsonb* annotations resolve against jakarta.json.bind-api 3.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 @JsonbSubtype mappings; no Jackson annotations; children implement the interface (tested by oneOfInterfaceMicroprofileJsonb).
    • Adds bin/configs/java-microprofile-oneof-interface-jsonb.yaml and the samples/client/petstore/java/microprofile-oneof-interface-jsonb project; 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.