{"record":{"id":"57a8e770d7cc567c","repo":"spring-projects/spring-security","slug":"an-error-occurred-writing-the-userinfo-response","errorCode":null,"errorMessage":"An error occurred writing the UserInfo response: ${ex.getMessage()}","messagePattern":"An error occurred writing the UserInfo response: (.+?)","errorType":"http","errorClass":"HttpMessageNotWritableException","httpStatus":500,"severity":"error","filePath":"oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/http/converter/OidcUserInfoHttpMessageConverter.java","lineNumber":97,"sourceCode":"\t\t\t\t.read(STRING_OBJECT_MAP.getType(), null, inputMessage);\n\t\t\treturn this.userInfoConverter.convert(userInfoParameters);\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new HttpMessageNotReadableException(\n\t\t\t\t\t\"An error occurred reading the UserInfo response: \" + ex.getMessage(), ex, inputMessage);\n\t\t}\n\t}\n\n\t@Override\n\tprotected void writeInternal(OidcUserInfo oidcUserInfo, HttpOutputMessage outputMessage)\n\t\t\tthrows HttpMessageNotWritableException {\n\t\ttry {\n\t\t\tMap<String, Object> userInfoResponseParameters = this.userInfoParametersConverter.convert(oidcUserInfo);\n\t\t\tthis.jsonMessageConverter.write(userInfoResponseParameters, STRING_OBJECT_MAP.getType(),\n\t\t\t\t\tMediaType.APPLICATION_JSON, outputMessage);\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new HttpMessageNotWritableException(\n\t\t\t\t\t\"An error occurred writing the UserInfo response: \" + ex.getMessage(), ex);\n\t\t}\n\t}\n\n\t/**\n\t * Sets the {@link Converter} used for converting the UserInfo parameters to an\n\t * {@link OidcUserInfo}.\n\t * @param userInfoConverter the {@link Converter} used for converting to an\n\t * {@link OidcUserInfo}\n\t */\n\tpublic final void setUserInfoConverter(Converter<Map<String, Object>, OidcUserInfo> userInfoConverter) {\n\t\tAssert.notNull(userInfoConverter, \"userInfoConverter cannot be null\");\n\t\tthis.userInfoConverter = userInfoConverter;\n\t}\n\n\t/**\n\t * Sets the {@link Converter} used for converting the {@link OidcUserInfo} to a\n\t * {@code Map} representation of the UserInfo.","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/http/converter/OidcUserInfoHttpMessageConverter.java#L79-L115","documentation":"This HttpMessageNotWritableException is thrown by OidcUserInfoHttpMessageConverter.writeInternal when converting the OidcUserInfo to parameters or serializing them to JSON fails. It wraps the root cause's message. The library considers any failure to render the UserInfo response as a non-writable message.","triggerScenarios":"The userInfoParametersConverter throws while converting OidcUserInfo claims, or the jsonMessageConverter fails writing the resulting Map<String,Object> as JSON to the output message.","commonSituations":"Custom UserInfo claim values that Jackson cannot serialize; a missing or misconfigured JSON converter; a custom converter bean throwing during conversion.","solutions":["Read the wrapped cause message to identify the actual failure","Check that a JSON converter (Jackson) is available and configured","Ensure all OidcUserInfo claim values are JSON-serializable primitives/collections","Replace any customized converter via setJsonMessageConverter()/setUserInfoParametersConverter() with a working one"],"exampleFix":"// before: non-serializable claim\nOidcUserInfo userInfo = new OidcUserInfo(Map.of(\"sub\", \"user\", \"obj\", new Object()));\n// after: JSON-friendly claims only\nOidcUserInfo userInfo = new OidcUserInfo(Map.of(\"sub\", \"user\"));","handlingStrategy":"try-catch","validationCode":"// Validate claims are JSON-serializable before building OidcUserInfo\nclaims.values().forEach(v -> new ObjectMapper().writeValueAsString(v));","typeGuard":"boolean isSerializableClaimSet(Map<String,Object> claims) {\n    try { new ObjectMapper().writeValueAsString(claims); return true; }\n    catch (JsonProcessingException e) { return false; }\n}","tryCatchPattern":"try {\n    converter.write(oidcUserInfo, null, outputMessage);\n} catch (HttpMessageNotWritableException e) {\n    logger.error(\"UserInfo write failed: {}\", e.getCause(), e);\n}","preventionTips":["Keep UserInfo claims to JSON-supported types (String, Number, Boolean, List, Map)","Do not replace the default JSON converter unless fully tested","Integration-test the UserInfo response rendering"],"tags":["http","json","openid-connect","userinfo"],"backgroundTag":"json-marshal-failed","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}