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:
PromptConfigJsonDiscriminatedUnionon the base class, listing all subclasses that are part of the union.PromptConfigJsonDiscriminatoron the discriminator property in the base class.PromptConfigJsonDiscriminatedUnionMemberon each subclass, specifying the discriminator value for that subclass.
@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
-
Element Details
-
value
String valueThe discriminator value for this subclass. This value must match the value of the discriminator field in the base class annotated withPromptConfigJsonDiscriminator.- Returns:
- The value that discriminates this subclass from other subclasses in the discriminated union.
-