{"record":{"id":"e9069a1444b245bf","repo":"spring-projects/spring-security","slug":"an-error-occurred-writing-the-openid-client-regist","errorCode":null,"errorMessage":"An error occurred writing the OpenID Client Registration: ${ex.getMessage()}","messagePattern":"An error occurred writing the OpenID Client Registration: (.+?)","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/OidcClientRegistrationHttpMessageConverter.java","lineNumber":108,"sourceCode":"\t\t\treturn this.clientRegistrationConverter.convert(clientRegistrationParameters);\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 OpenID Client Registration: \" + ex.getMessage(), ex, inputMessage);\n\t\t}\n\t}\n\n\t@Override\n\tprotected void writeInternal(OidcClientRegistration clientRegistration, HttpOutputMessage outputMessage)\n\t\t\tthrows HttpMessageNotWritableException {\n\t\ttry {\n\t\t\tMap<String, Object> clientRegistrationParameters = this.clientRegistrationParametersConverter\n\t\t\t\t.convert(clientRegistration);\n\t\t\tthis.jsonMessageConverter.write(clientRegistrationParameters, 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 OpenID Client Registration: \" + ex.getMessage(), ex);\n\t\t}\n\t}\n\n\t/**\n\t * Sets the {@link Converter} used for converting the OpenID Client Registration\n\t * parameters to an {@link OidcClientRegistration}.\n\t * @param clientRegistrationConverter the {@link Converter} used for converting to an\n\t * {@link OidcClientRegistration}\n\t */\n\tpublic final void setClientRegistrationConverter(\n\t\t\tConverter<Map<String, Object>, OidcClientRegistration> clientRegistrationConverter) {\n\t\tAssert.notNull(clientRegistrationConverter, \"clientRegistrationConverter cannot be null\");\n\t\tthis.clientRegistrationConverter = clientRegistrationConverter;\n\t}\n\n\t/**\n\t * Sets the {@link Converter} used for converting the {@link OidcClientRegistration}","sourceCodeStart":90,"sourceCodeEnd":126,"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/OidcClientRegistrationHttpMessageConverter.java#L90-L126","documentation":"OidcClientRegistrationHttpMessageConverter.writeInternal serializes an OidcClientRegistration to the HTTP response. If converting the registration to a parameter map or writing it as JSON fails, the exception is wrapped in an HttpMessageNotWritableException with the message \"An error occurred writing the OpenID Client Registration: <cause message>\". It indicates the server could not render a client registration (typically the registration response) as JSON.","triggerScenarios":"The clientRegistrationEndpoint completes registration and writeInternal is invoked, but OidcClientRegistrationToParametersConverter or the underlying JSON message converter throws — e.g. a null/unset converter, a custom converter that throws, or a configured MappingJackson2HttpMessageConverter that cannot serialize a value in the registration.","commonSituations":"Spring MVC/Spring Security versions where the default JSON converter is unavailable or misconfigured; overriding the converter via HttpMessageConverters with one that rejects the output; a custom converter returning an incompatible map; response stream already committed/closed by a filter.","solutions":["Check the nested cause to identify which conversion or serialization step failed.","Ensure a functioning JSON HttpMessageConverter (e.g. MappingJackson2HttpMessageConverter) is on the classpath and registered on the endpoint.","Review any custom clientRegistrationParametersConverter registered on OidcClientRegistrationHttpMessageConverter for bugs or incompatibility.","Verify no earlier filter/interceptor has committed or closed the response output stream before the endpoint writes."],"exampleFix":"// before (custom converter throws on null client_id issued value)\nreturn Map.of(\"client_id\", registration.getClientId(), \"redirect_uris\", registration.getRedirectUris());\n\n// after (handle absent values and only include set fields)\nMap<String, Object> params = new HashMap<>();\nparams.put(\"client_id\", registration.getClientId());\nif (!registration.getRedirectUris().isEmpty()) {\n    params.put(\"redirect_uris\", registration.getRedirectUris());\n}\nreturn params;","handlingStrategy":"try-catch","validationCode":"boolean canSerialize(OidcClientRegistration reg) {\n    return reg != null && reg.getClientId() != null;\n}","typeGuard":null,"tryCatchPattern":"try {\n    converter.write(registration, MediaType.APPLICATION_JSON, outputMessage);\n} catch (HttpMessageNotWritableException ex) {\n    log.error(\"Failed to write client registration response: {}\", ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage(), ex);\n    response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value());\n}","preventionTips":["Keep a working JSON message converter (Jackson) on the classpath and registered.","Test any custom clientRegistrationParametersConverter against real OidcClientRegistration values.","Ensure filters/interceptors do not commit the response before the endpoint writes."],"tags":["http","json","serialization","oidc","client-registration"],"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-14T11:17:12.474Z"}