Skip to content

Commit b10a370

Browse files
committed
fix: Remove unnecessary MapStruct conversion
1 parent cb084ec commit b10a370

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package io.a2a.grpc.mapper;
22

3+
import org.mapstruct.BeanMapping;
4+
import org.mapstruct.Builder;
35
import org.mapstruct.Mapper;
6+
import org.mapstruct.Mapping;
47

58
/**
69
* Mapper between {@link io.a2a.spec.SubscribeToTaskRequest} and {@link io.a2a.grpc.SubscribeToTaskRequest}.
@@ -11,9 +14,9 @@
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})
1922
public 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
}

spec/src/main/java/io/a2a/spec/SubscribeToTaskRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public SubscribeToTaskRequest(Object id, TaskIdParams params) {
5757
this(null, id, METHOD, params);
5858
}
5959

60+
public static Builder builder() {
61+
return new Builder();
62+
}
63+
6064
public static class Builder {
6165
private String jsonrpc;
6266
private Object id;

0 commit comments

Comments
 (0)