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
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);
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondata()Returns the value of thedatarecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.metadata()Returns the value of themetadatarecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
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
Compact constructor with validation.Note: For mutable data types (Map, List), callers should ensure immutability by using
Map.copyOf()orList.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
Constructor.- Parameters:
data- the structured data (supports JSON objects, arrays, primitives, and not null)- Throws:
IllegalArgumentException- if data is null
-
-
Method Details
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
data
Returns the value of thedatarecord component.- Returns:
- the value of the
datarecord component
-
metadata
Returns the value of themetadatarecord component.- Returns:
- the value of the
metadatarecord component
-