Class DiscriminatedTrait

java.lang.Object
software.amazon.smithy.model.traits.AbstractTrait
software.amazon.smithy.model.traits.DiscriminatedTrait
All Implemented Interfaces:
FromSourceLocation, ToNode, ToShapeId, Trait

public final class DiscriminatedTrait extends AbstractTrait
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.

  • Field Details

    • ID

      public static final ShapeId ID
    • DEFAULT_VALUE

      public static final String DEFAULT_VALUE
      The discriminator field name used when the trait is applied without a value.
      See Also:
  • Constructor Details

    • DiscriminatedTrait

      public DiscriminatedTrait(String value, FromSourceLocation sourceLocation)
    • DiscriminatedTrait

      public DiscriminatedTrait(String value)
    • DiscriminatedTrait

      public DiscriminatedTrait()
      Creates a trait that uses the default discriminator field name.
  • Method Details

    • getValue

      public String getValue()
      Returns:
      the name of the field that identifies the active union member.
    • createNode

      protected Node createNode()
      Description copied from class: AbstractTrait
      The 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:
      createNode in class AbstractTrait
      Returns:
      Returns the trait as a node.