11package io .a2a .grpc .mapper ;
22
3+ import org .mapstruct .BeanMapping ;
4+ import org .mapstruct .Builder ;
35import org .mapstruct .Mapper ;
6+ import org .mapstruct .Mapping ;
47
58/**
69 * Mapper between {@link io.a2a.spec.SubscribeToTaskRequest} and {@link io.a2a.grpc.SubscribeToTaskRequest}.
1114 * <li>Proto: Simple request with name field in format "tasks/{task_id}"</li>
1215 * </ul>
1316 * <p>
14- * Note: The domain object is a complete JSONRPC request, while the proto is just the gRPC
15- * request parameters. The JSONRPC envelope (id, jsonrpc, method) is handled separately
16- * by the transport layer .
17+ * Uses {@link ResourceNameParser} to convert between task ID and resource name format.
18+ * The domain JSONRPC envelope fields (id, jsonrpc, method) are populated with defaults
19+ * by the Builder when converting from proto .
1720 */
1821@ Mapper (config = A2AProtoMapperConfig .class , uses = {TaskIdParamsMapper .class })
1922public interface SubscribeToTaskRequestMapper {
@@ -27,28 +30,21 @@ public interface SubscribeToTaskRequestMapper {
2730 * @param domain the domain SubscribeToTaskRequest
2831 * @return the proto SubscribeToTaskRequest
2932 */
30- default io .a2a .grpc .SubscribeToTaskRequest toProto (io .a2a .spec .SubscribeToTaskRequest domain ) {
31- if (domain == null || domain .getParams () == null || domain .getParams ().id () == null ) {
32- return null ;
33- }
34- return io .a2a .grpc .SubscribeToTaskRequest .newBuilder ()
35- .setName (ResourceNameParser .defineTaskName (domain .getParams ().id ()))
36- .build ();
37- }
33+ @ Mapping (target = "name" , expression = "java(ResourceNameParser.defineTaskName(domain.getParams().id()))" )
34+ io .a2a .grpc .SubscribeToTaskRequest toProto (io .a2a .spec .SubscribeToTaskRequest domain );
3835
3936 /**
4037 * Converts proto SubscribeToTaskRequest to domain SubscribeToTaskRequest.
4138 * Extracts the task ID from the name field and creates a TaskIdParams.
39+ * The JSONRPC envelope fields (id, jsonrpc, method) are populated with defaults by the Builder.
4240 *
4341 * @param proto the proto SubscribeToTaskRequest
4442 * @return the domain SubscribeToTaskRequest
4543 */
46- default io .a2a .spec .SubscribeToTaskRequest fromProto (io .a2a .grpc .SubscribeToTaskRequest proto ) {
47- if (proto == null || proto .getName () == null ) {
48- return null ;
49- }
50- return new io .a2a .spec .SubscribeToTaskRequest .Builder ()
51- .params (new io .a2a .spec .TaskIdParams (ResourceNameParser .extractTaskId (proto .getName ())))
52- .build ();
53- }
44+ @ BeanMapping (builder = @ Builder (buildMethod = "build" ))
45+ @ Mapping (target = "params" , expression = "java(new io.a2a.spec.TaskIdParams(ResourceNameParser.extractTaskId(proto.getName())))" )
46+ @ Mapping (target = "id" , ignore = true ) // Builder sets UUID default
47+ @ Mapping (target = "jsonrpc" , ignore = true ) // Builder sets "2.0" default
48+ @ Mapping (target = "method" , ignore = true ) // Builder sets "SubscribeToTask" default
49+ io .a2a .spec .SubscribeToTaskRequest fromProto (io .a2a .grpc .SubscribeToTaskRequest proto );
5450}
0 commit comments