{"record":{"id":"cd4269ab8b58062d","repo":"spring-projects/spring-ai","slug":"invalid-json-format-for-the-input-request","errorCode":null,"errorMessage":"Invalid JSON format for the input request: ","messagePattern":"Invalid JSON format for the input request: ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java","lineNumber":238,"sourceCode":"\t/**\n\t * Internal method to invoke the model and return the response.\n\t * https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html\n\t * https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html\n\t * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/bedrockruntime/BedrockRuntimeClient.html#invokeModel\n\t *\n\t * @param request Model invocation request.\n\t * @param clazz The response class type\n\t * @return The model invocation response.\n\t *\n\t */\n\tprotected O internalInvocation(I request, Class<O> clazz) {\n\n\t\tSdkBytes body;\n\t\ttry {\n\t\t\tbody = SdkBytes.fromUtf8String(this.jsonMapper.writeValueAsString(request));\n\t\t}\n\t\tcatch (JacksonException e) {\n\t\t\tthrow new IllegalArgumentException(\"Invalid JSON format for the input request: \" + request, e);\n\t\t}\n\n\t\tInvokeModelRequest invokeRequest = InvokeModelRequest.builder()\n\t\t\t\t.modelId(this.modelId)\n\t\t\t\t.body(body)\n\t\t\t\t.build();\n\n\t\tInvokeModelResponse response = this.client.invokeModel(invokeRequest);\n\n\t\tString responseBody = response.body().asString(StandardCharsets.UTF_8);\n\n\t\ttry {\n\t\t\treturn this.jsonMapper.readValue(responseBody, clazz);\n\t\t}\n\t\tcatch (JacksonException e) {\n\t\t\tthrow new IllegalArgumentException(\"Invalid JSON format for the response: \" + responseBody, e);\n\t\t}\n\t}","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java#L220-L256","documentation":"internalInvocation serializes the request object to JSON with the configured Jackson ObjectMapper before sending it to Bedrock's InvokeModel API. If Jackson cannot serialize the request (JacksonException), the library wraps it in an IllegalArgumentException, indicating the request object is not JSON-mappable — usually a configuration/programming error in the request object.","triggerScenarios":"Invoking a Bedrock model via AbstractBedrockApi when the request object contains unserializable types, mismatched Jackson modules, or fails getter access, causing writeValueAsString to throw.","commonSituations":"Custom request DTOs without Jackson-compatible getters; missing jackson modules (e.g. Java 8/records support); passing objects of the wrong generic type I; classpath Jackson version conflicts.","solutions":["Inspect the wrapped cause (e) for the exact Jackson serialization failure and fix the offending field/getter","Ensure the request object matches the API class's expected request type and has Jackson-visible accessors","Align Jackson versions/modules on the classpath with those used by spring-ai-bedrock"],"exampleFix":"// before\nrecord MyRequest(SomeUnserializable obj) {} // fails serialization\n// after\nrecord MyRequest(@JsonProperty(\"input\") String input) {} // simple JSON-friendly types","handlingStrategy":"try-catch","validationCode":"try { new ObjectMapper().writeValueAsString(request); } catch (JacksonException e) { throw new IllegalStateException(\"Request not JSON-serializable: \" + e.getMessage()); }","typeGuard":null,"tryCatchPattern":"try { api.internalInvocation(request, responseType); } catch (IllegalArgumentException e) { if (e.getCause() instanceof JacksonException je) { log.error(\"Serialize failed: {}\", je.getMessage()); } throw e; }","preventionTips":["Keep request DTOs to JSON-friendly types with proper accessors","Ensure required Jackson modules (records/Java8) are on the classpath","Align Jackson versions with those used by spring-ai-bedrock"],"tags":["bedrock","jackson","serialization","illegal-argument"],"backgroundTag":"json-marshal-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}