Class JsonMappingException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
IdJsonMappingException

public class JsonMappingException extends JsonProcessingException
Exception for JSON mapping errors when converting between JSON and Java objects.

This exception serves as a replacement for Jackson's JsonMappingException, allowing the A2A Java SDK to remain independent of any specific JSON library implementation. It represents errors that occur during the mapping phase of deserialization or serialization, such as type mismatches, invalid values, or constraint violations.

This exception extends JsonProcessingException and is used for more specific mapping-related errors compared to general parsing errors.

Usage example:


 try {
     Task task = JsonUtil.fromJson(json, Task.class);
     if (task.id() == null) {
         throw new JsonMappingException(null, "Task ID cannot be null");
     }
 } catch (JsonProcessingException e) {
     throw new JsonMappingException(null, "Invalid task format: " + e.getMessage(), e);
 }
 
See Also:
  • Constructor Details

    • JsonMappingException

      public JsonMappingException(@Nullable Object reference, String message)
      Constructs a new JsonMappingException with the specified reference and message.

      The reference parameter can be used to provide context about where the mapping error occurred (e.g., a field name, path, or parser reference). It can be null if no specific reference is available.

      Parameters:
      reference - optional reference object providing context for the error (may be null)
      message - the detail message explaining the mapping error
    • JsonMappingException

      public JsonMappingException(@Nullable Object reference, String message, @Nullable Throwable cause)
      Constructs a new JsonMappingException with the specified reference, message, and cause.

      The reference parameter can be used to provide context about where the mapping error occurred (e.g., a field name, path, or parser reference). It can be null if no specific reference is available.

      Parameters:
      reference - optional reference object providing context for the error (may be null)
      message - the detail message explaining the mapping error
      cause - the underlying cause of the mapping error (may be null)
    • JsonMappingException

      public JsonMappingException(String message, @Nullable Throwable cause)
      Constructs a new JsonMappingException with the specified message and cause.

      This constructor is provided for compatibility when no reference object is needed.

      Parameters:
      message - the detail message explaining the mapping error
      cause - the underlying cause of the mapping error (may be null)
    • JsonMappingException

      public JsonMappingException(String message)
      Constructs a new JsonMappingException with the specified message.

      This constructor is provided for compatibility when no reference object is needed.

      Parameters:
      message - the detail message explaining the mapping error
  • Method Details

    • getReference

      public @Nullable Object getReference()
      Returns the reference object that provides context for the mapping error.

      This may be null if no specific reference was available when the exception was created.

      Returns:
      the reference object, or null if not available