Package io.a2a.spec

Record Class DataPart

java.lang.Object
java.lang.Record
io.a2a.spec.DataPart
Record Components:
data - the structured data (required, supports JSON objects, arrays, primitives, and null)
metadata - additional metadata for the part
All Implemented Interfaces:
Part<Object>

public record DataPart(Object data, @Nullable Map<String,Object> metadata) extends Record implements Part<Object>
Represents a structured data content part within a Message or Artifact.

DataPart contains arbitrary JSON data for machine-to-machine communication. It is used when content needs to be processed programmatically rather than displayed as text, such as API responses, configuration data, analysis results, or structured metadata.

The data can be any valid JSON value:

  • JSON objects: Map<String, Object>
  • JSON arrays: List<Object>
  • Primitives: String, Number, Boolean
  • Null values: null

Example usage:


 // JSON object
 DataPart obj = new DataPart(Map.of(
     "status", "success",
     "count", 42,
     "items", List.of("item1", "item2")
 ));

 // JSON array
 DataPart array = new DataPart(List.of("item1", "item2", "item3"));

 // Primitive value
 DataPart primitive = new DataPart(42);
 
See Also:
  • Field Details

    • DATA

      public static final String DATA
      The JSON member name discriminator for data parts: "data".

      In protocol v1.0+, this constant defines the JSON member name used for serialization: { "data": { "data": { "temperature": 22.5, "unit": "C" } } }

      See Also:
  • Constructor Details

    • DataPart

      public DataPart(Object data, @Nullable Map<String,Object> metadata)
      Compact constructor with validation.

      Note: For mutable data types (Map, List), callers should ensure immutability by using Map.copyOf() or List.copyOf() before passing to this constructor.

      Parameters:
      data - the structured data (supports JSON objects, arrays, primitives, and null)
      Throws:
      IllegalArgumentException - if data is null
    • DataPart

      public DataPart(Object data)
      Constructor.
      Parameters:
      data - the structured data (supports JSON objects, arrays, primitives, and not null)
      Throws:
      IllegalArgumentException - if data is null
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • data

      public Object data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component
    • metadata

      public @Nullable Map<String,Object> metadata()
      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component