Annotation Interface JsonDiscriminatorField


@Target(TYPE) @Retention(RUNTIME) public @interface JsonDiscriminatorField
Русский: Аннотация указывает, что класс/интерфейс должен быть запечатанным (sealed), а его тип десериализации будет зависеть от поля value(), работает в связке с аннотацией JsonDiscriminatorValue.
English: Annotation indicates that class/interface must be sealed and its deserialized type is will depend on value() field, works in conjunctions with JsonDiscriminatorValue annotation

Пример / Example:

 @Json
 @JsonDiscriminatorField("type")
 public sealed interface SealedDto {

     @JsonDiscriminatorValue("type1")
     record FirstType(String value) implements SealedDto {}

     @JsonDiscriminatorValue("type2")
     record SecondType(String val, int dig) implements SealedDto {}
 }
 

Json for type1:


 { "type": "type1", "value": "Movies" }
 

Json for type2:


 { "type": "type2", "val": "Movies", "dig": 1 }
 
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
     
  • Element Details

    • value

      String value
      Returns:
      Русский: Имя поле которое будет определять тип десериализуемого значения
      English: Name of the field that will determine the type of the deserializable value