Annotation Type 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:
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.
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
-
Element Details
-
value
Class<?>[] valueA list of subclasses that are part of this discriminated union. Each subclass must be annotated withPromptConfigJsonDiscriminatedUnionMemberto indicate its discriminator value.- Returns:
- An array of classes that are part of this discriminated union.
-