File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
spec-grpc/src/main/java/io/a2a/grpc/mapper Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1414import org .mapstruct .Mapper ;
1515import org .mapstruct .Named ;
1616
17+ import io .a2a .spec .InvalidParamsError ;
18+
1719/**
1820 * Common field mapping utilities shared across all mappers.
1921 * <p>
@@ -46,6 +48,24 @@ default String emptyToNull(String value) {
4648 return (value == null || value .isEmpty ()) ? null : value ;
4749 }
4850
51+ /**
52+ * Validates that a required string field is not null or empty.
53+ * <p>
54+ * Throws an exception if the protobuf string is null or empty.
55+ * Use this with {@code @Mapping(qualifiedByName = "requireNonEmpty")}.
56+ *
57+ * @param value the protobuf string value
58+ * @return the value if not null/empty
59+ * @throws IllegalArgumentException if value is null or empty
60+ */
61+ @ Named ("requireNonEmpty" )
62+ default String requireNonEmpty (String value ) {
63+ if (value == null || value .isEmpty ()) {
64+ throw new InvalidParamsError ("Required field cannot be null or empty" );
65+ }
66+ return value ;
67+ }
68+
4969 /**
5070 * Converts null strings to empty strings for protobuf.
5171 * <p>
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public interface MessageMapper {
3636 * Uses Builder pattern explicitly configured via @BeanMapping.
3737 */
3838 @ BeanMapping (builder = @ Builder (buildMethod = "build" ))
39- @ Mapping (target = "messageId" , source = "messageId" , qualifiedByName = "emptyToNull " )
39+ @ Mapping (target = "messageId" , source = "messageId" , qualifiedByName = "requireNonEmpty " )
4040 @ Mapping (target = "contextId" , source = "contextId" , qualifiedByName = "emptyToNull" )
4141 @ Mapping (target = "taskId" , source = "taskId" , qualifiedByName = "emptyToNull" )
4242 @ Mapping (target = "metadata" , source = "metadata" , qualifiedByName = "metadataFromProto" )
You can’t perform that action at this time.
0 commit comments