Class DiscriminatedTrait
java.lang.Object
software.amazon.smithy.model.traits.AbstractTrait
software.amazon.smithy.model.traits.DiscriminatedTrait
- All Implemented Interfaces:
FromSourceLocation,ToNode,ToShapeId,Trait
Indicates that this union is serialized as an internally tagged union.
The value of the trait is the name of the field that identifies the active union member. The value is optional
when applying the trait; a bare @discriminated is equivalent to @discriminated("__type"). An explicit
null value, which a model loader passes to the provider in the same way as a bare trait, is also equivalent
to @discriminated("__type"). This is handled here rather than by extending StringTrait because a
string trait requires an explicit value, and a @default on the trait's definition is not applied to traits.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a trait that uses thedefaultdiscriminator field name.DiscriminatedTrait(String value) DiscriminatedTrait(String value, FromSourceLocation sourceLocation) -
Method Summary
Methods inherited from class software.amazon.smithy.model.traits.AbstractTrait
equals, getSourceLocation, hashCode, setNodeCache, toNode, toShapeId, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface software.amazon.smithy.model.traits.Trait
isSynthetic
-
Field Details
-
ID
-
DEFAULT_VALUE
The discriminator field name used when the trait is applied without a value.- See Also:
-
-
Constructor Details
-
DiscriminatedTrait
-
DiscriminatedTrait
-
DiscriminatedTrait
public DiscriminatedTrait()Creates a trait that uses thedefaultdiscriminator field name.
-
-
Method Details
-
getValue
- Returns:
- the name of the field that identifies the active union member.
-
createNode
Description copied from class:AbstractTraitThe result of toNode is used for hashCodes and equality. Subclasses must implement createNode to turn the trait into a Node. This is then cached for subsequent retrievals.- Specified by:
createNodein classAbstractTrait- Returns:
- Returns the trait as a node.
-