[Java][JAX-RS] Add JSON-B discriminator deserialization support

DE
1d ago
+7211-18

Summary

Adds JSON-B discriminator-based polymorphic deserialization support to the Java JAX-RS Spec server generator.

Depends on #25662. This is a follow-up to the abstract models and sealed discriminator hierarchies PR. Please review and merge #25662 first.

Until #25662 is merged, this PR includes both commits in the GitHub comparison. The JSON-B-specific changes are contained in commit 88ef700f952.

Changes

  • Add the jsonbDiscriminatorDeserializers generator option.
  • Generate JSON-B deserializers for discriminator-based polymorphic model hierarchies.
  • Support nested polymorphic values in lists, maps, and sets.
  • Support @JsonbCreator, inherited models, oneOf interfaces, and discriminator mappings.
  • Add the JsonbPolymorphismProcessor and corresponding Mustache templates.
  • Add generator tests and OpenAPI specifications covering polymorphic JSON-B deserialization.
  • Add a generated JAX-RS Spec JSON-B sample and include it in the sample CI workflow.
  • Update generator documentation.

Validation

  • ./mvnw clean package — BUILD SUCCESS (all 8 modules; Maven Central used via a separate settings file).
  • Targeted JAX-RS Spec tests — 239 tests, 0 failures, 0 errors, 1 skipped.
  • ./bin/generate-samples.sh bin/configs/jaxrs-spec-sealed-jsonb.yaml — successful, no generated changes.
  • ./bin/utils/export_docs_generators.sh — completed, no generated changes.

PR checklist

  • Read the contribution guidelines.
  • Run Maven build and tests.
  • Regenerate the relevant JAX-RS Spec sample.
  • Export generator documentation.
  • Commit all changes.

Dependency

PR #25662 introduces the abstract and sealed model support used by this implementation. After #25662 is merged, this PR should contain only the JSON-B-specific changes relative to master.


Summary by cubic

Adds JSON-B discriminator-based polymorphic deserialization to the JAX-RS Spec server generator. Previously, discriminator hierarchies deserialized as their declared type; now the new jsonbDiscriminatorDeserializers option generates deserializers that resolve the concrete class from the discriminator value. This builds on the abstract models and sealed hierarchy support and should be reviewed and merged after that PR.

New Features

  • Generates JSON-B deserializers for discriminator-based hierarchies, including oneOf interfaces, inherited models, @JsonbCreator, and discriminator mappings.
  • Resolves polymorphic values nested in lists, sets, and maps, with container deserializers where the JSON-B implementation needs them.
  • Adds generator tests, test specifications, a generated sample with CI coverage, and updated generator docs.
  • With Yasson before 3.0.5, root containers such as Map<String, Pet> (also List<Pet> on 3.0.2) are not covered; Johnzon 2.0.2 to 2.2.0 has a missing-required-container limitation.