luigidemasi commented on code in PR #23711: URL: https://github.com/apache/camel/pull/23711#discussion_r3348401575
########## components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/model/Task.java: ########## @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.a2a.model; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +/** + * A2A protocol task. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Task( + String id, + String contextId, + TaskStatus status, + List<Artifact> artifacts, + List<Message> history, + Map<String, Object> metadata) { + + /** + * Convenience accessor for Camel OGNL: ${body.latest.parts[0].text} + */ + public Message latest() { + return (history != null && !history.isEmpty()) ? history.get(history.size() - 1) : null; + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(Task task) { + return new Builder() + .id(task.id) + .contextId(task.contextId) + .status(task.status) + .artifacts(task.artifacts != null ? new ArrayList<>(task.artifacts) : null) + .history(task.history != null ? new ArrayList<>(task.history) : null) + .metadata(task.metadata != null ? new HashMap<>(task.metadata) : null); Review Comment: This is a protocol model class serialized by Jackson, `null` fields are omitted from JSON output while empty collections serialize as `[]` / `{}`. The A2A spec distinguishes between "field absent" (not provided) and "field present but empty" (explicitly no items), so the copy constructor preserves the original semantics. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
