{"record":{"id":"2a1959b3020de481","repo":"spring-projects/spring-ai","slug":"jacksonexception-wrapped-illegalstateexception","errorCode":null,"errorMessage":"JacksonException (wrapped IllegalStateException)","messagePattern":"JacksonException \\(wrapped IllegalStateException\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-ai-model/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java","lineNumber":241,"sourceCode":"\t\treturn String.format(template, this.jsonSchema);\n\t}\n\n\t/**\n\t * Provides the generated JSON schema for the target type.\n\t * @return The generated JSON schema.\n\t */\n\t@Override\n\tpublic String getJsonSchema() {\n\t\treturn this.jsonSchema;\n\t}\n\n\tpublic Map<String, Object> getJsonSchemaMap() {\n\t\ttry {\n\t\t\treturn this.jsonMapper.readValue(this.jsonSchema, Map.class);\n\t\t}\n\t\tcatch (JacksonException ex) {\n\t\t\tlogger.error(\"Could not parse the JSON Schema to a Map object\", ex);\n\t\t\tthrow new IllegalStateException(ex);\n\t\t}\n\t}\n\n}\n","sourceCodeStart":223,"sourceCodeEnd":246,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-model/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java#L223-L246","documentation":"BeanOutputConverter.getJsonSchemaMap() parses the generated JSON Schema string with Jackson into a Map; if the schema string is not parseable, JacksonException is logged and rethrown as IllegalStateException. This means the internally produced JSON Schema is malformed or the jsonSchema field was set to invalid JSON.","triggerScenarios":"Calling getJsonSchemaMap() on a BeanOutputConverter whose jsonSchema string was never generated, was overwritten with invalid JSON, or a target class whose generated schema fails Jackson parsing.","commonSituations":"Manually constructing/patching a BeanOutputConverter with a hand-written schema string; using exotic generic type parameters that break schema generation; older Spring AI versions where schema generation produced invalid JSON for some types.","solutions":["Let BeanOutputConverter generate the schema from the target type instead of injecting a custom jsonSchema string.","Validate the target class's schema with getJsonSchema() and a JSON validator to find the malformed portion.","Upgrade Spring AI to a version with fixed schema generation for your types.","Wrap getJsonSchemaMap() in try-catch and fall back to parsing getJsonSchema() defensively."],"exampleFix":"// before\nnew BeanOutputConverter<Record>(type, null, \"not-json\", ...).getJsonSchemaMap();\n// after\nBeanOutputConverter<Record> c = new BeanOutputConverter<>(type);\nString schema = c.getJsonSchema(); // generated, guaranteed valid JSON","handlingStrategy":"try-catch","validationCode":"try { new ObjectMapper().readTree(converter.getJsonSchema()); } catch (Exception e) { /* schema invalid — regenerate or fix type */ }","typeGuard":null,"tryCatchPattern":"try { return converter.getJsonSchemaMap(); } catch (IllegalStateException e) { logger.warn(\"JSON schema unparseable; using raw schema string\", e); return Map.of(); }","preventionTips":["Don't hand-inject jsonSchema strings; let BeanOutputConverter generate them","Keep target classes as simple records/POJOs with Jackson-friendly types","Pin a Spring AI version known to generate valid schemas for your types","Sanity-check getJsonSchema() output in tests"],"tags":["json","schema","jackson"],"backgroundTag":"json-parse-error","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"}