Class JsonMappingException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
IdJsonMappingException
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 Summary
ConstructorsConstructorDescriptionJsonMappingException(@Nullable Object reference, String message) Constructs a new JsonMappingException with the specified reference and message.JsonMappingException(@Nullable Object reference, String message, @Nullable Throwable cause) Constructs a new JsonMappingException with the specified reference, message, and cause.JsonMappingException(String message) Constructs a new JsonMappingException with the specified message.JsonMappingException(String message, @Nullable Throwable cause) Constructs a new JsonMappingException with the specified message and cause. -
Method Summary
Modifier and TypeMethodDescription@Nullable ObjectReturns the reference object that provides context for the mapping error.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
JsonMappingException
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
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 errorcause- the underlying cause of the mapping error (may be null)
-
JsonMappingException
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 errorcause- the underlying cause of the mapping error (may be null)
-
JsonMappingException
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
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
-