Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A2aproject A2a java Grpc Utils Classes

From Leeroopedia
Knowledge Sources
Domains gRPC, JSON_RPC, Protocol_Conversion
Last Updated 2026-10-30 00:00 GMT

Overview

Concrete utility classes for converting between gRPC protobuf messages, JSON-RPC envelopes, and A2A spec records across all transport layers.

Description

The `spec-grpc/utils` package provides three key utility classes:

  • ProtoUtils: Central conversion facade with nested ToProto and FromProto static classes that use the MapStruct mappers to convert between spec records and protobuf messages. Used by GrpcTransport, JSONRPCTransport, and RestTransport.
  • JSONRPCUtils: Handles JSON-RPC 2.0 protocol envelope construction, parsing, and error mapping. Converts between JSON-RPC request/response envelopes and protobuf/spec objects. Used by JSONRPCTransport and server-side JSONRPCHandler.
  • ProtoJsonUtils: Thin wrapper around protobuf's JsonFormat for JSON-to-protobuf conversion (used by RestTransport).

Usage

  • ProtoUtils: Called by all three transports (gRPC, JSON-RPC, REST) to convert spec records to wire format and back
  • JSONRPCUtils: Used by JSON-RPC transport and handler for envelope construction and parsing
  • ProtoJsonUtils: Used by REST transport for JSON ↔ protobuf conversion via JsonFormat

Code Reference

Source Location

  • Repository: a2a-java
  • Directory: `spec-grpc/src/main/java/org/a2aproject/sdk/grpc/utils/`

Key Files

File Lines Role
ProtoUtils.java 356 Spec ↔ protobuf conversion facade
JSONRPCUtils.java 634 JSON-RPC envelope construction/parsing
ProtoJsonUtils.java 39 JSON ↔ protobuf wrapper

Signature

// ProtoUtils - conversion facade
public class ProtoUtils {
    public static class ToProto {
        public static SendMessageRequest sendMessageRequest(MessageSendParams params);
        public static GetTaskRequest getTaskRequest(TaskQueryParams params);
        public static CancelTaskRequest cancelTaskRequest(CancelTaskParams params);
        public static SubscribeToTaskRequest subscribeToTaskRequest(TaskIdParams params);
        // ... all message types
    }
    public static class FromProto {
        public static EventKind message(org.a2aproject.sdk.grpc.Message proto);
        public static Task task(org.a2aproject.sdk.grpc.Task proto);
        public static StreamingEventKind streamResponse(StreamResponse proto);
        // ... all message types
    }
}

// JSONRPCUtils - JSON-RPC protocol handling
public class JSONRPCUtils {
    // Request envelope construction, response parsing, error mapping
    // Used by JSONRPCTransport and JSONRPCHandler
}

Import

import org.a2aproject.sdk.grpc.utils.ProtoUtils;
import org.a2aproject.sdk.grpc.utils.JSONRPCUtils;

I/O Contract

Inputs

Name Type Required Description
params Spec records Yes Domain model records
proto Protobuf messages Yes Wire format messages
json String Yes (JSONRPCUtils) JSON-RPC envelope string

Outputs

Name Type Description
ToProto.* Protobuf message Spec record → protobuf
FromProto.* Spec record Protobuf → spec record
JSONRPCUtils JSON string / spec object JSON-RPC envelope ↔ domain

Usage Examples

ProtoUtils Conversion

import org.a2aproject.sdk.grpc.utils.ProtoUtils;

// Convert spec params to protobuf for gRPC transport
SendMessageRequest protoRequest =
    ProtoUtils.ToProto.sendMessageRequest(messageSendParams);

// Convert protobuf response back to spec
EventKind result = ProtoUtils.FromProto.message(protoResponse.getMessage());
if (result instanceof Task task) {
    System.out.println("Task state: " + task.status().state());
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment