Annotation Type PromptConfigJsonDiscriminatedUnion


@Documented @Target(TYPE) @Retention(RUNTIME) public @interface PromptConfigJsonDiscriminatedUnion
Annotation for model classes that represent the abstract base class of a discriminated union, intended for use with the JsonConfig mixin for prompt service handlers.

To properly serialize and deserialize discriminated unions, you must place the following 3 annotations:

For example:

A discriminated union is a set of classes that share a common base class and are distinguished by a discriminator property. The discriminator property is a field in the base class that contains a value that indicates which subclass should be instantiated when deserializing a JSON object.

@PromptConfigJsonDiscriminatedUnion({BananaSplit.class})
public class Sweets {
  // other fields needed by this class
  @PromptConfigJsonDiscriminator
  protected String type;
}

@PromptConfigJsonDiscriminatedUnionMember("banana_split")
public class BananaSplit extends Sweets {
  // other fields needed by this class
  public BananaSplit() {
      this.type = "banana_split";
  }
}

@PromptConfigJsonDiscriminatedUnionMember("apple_pie")
public class ApplePie extends Sweets {
  // other fields needed by this class
  public ApplePie() {
   this.type = "apple_pie";
  }
}
In this example, we'd expect the JSON object to contain the "type" field. If the field's value is "banana_split", then we should deserialize the object into an instance of the BananaSplit class, and if the field's value is "apple_pie", then we should deserialize the object into an instance of the ApplePie class.
Since:
8.5.0
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Class<?>[]
    A list of subclasses that are part of this discriminated union.
  • Element Details

    • value

      Class<?>[] value
      A list of subclasses that are part of this discriminated union. Each subclass must be annotated with PromptConfigJsonDiscriminatedUnionMember to indicate its discriminator value.
      Returns:
      An array of classes that are part of this discriminated union.