Annotation Type PromptConfigJsonDiscriminatedUnionMember


@Documented @Target(TYPE) @Retention(RUNTIME) public @interface PromptConfigJsonDiscriminatedUnionMember
Annotation for a model class that represents a subclass of a discriminated union, intended for use with the JsonConfig mixin for prompt service handlers.

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.

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

For example:
@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
    The discriminator value for this subclass.
  • Element Details

    • value

      String value
      The discriminator value for this subclass. This value must match the value of the discriminator field in the base class annotated with PromptConfigJsonDiscriminator.
      Returns:
      The value that discriminates this subclass from other subclasses in the discriminated union.