{"record":{"id":"30b44ca7062287eb","repo":"spring-projects/spring-security","slug":"an-error-occurred-writing-the-openid-provider-conf","errorCode":null,"errorMessage":"An error occurred writing the OpenID Provider Configuration: ${ex.getMessage()}","messagePattern":"An error occurred writing the OpenID Provider Configuration: (.+?)","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/OidcProviderConfigurationHttpMessageConverter.java","lineNumber":100,"sourceCode":"\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 Provider Configuration: \" + ex.getMessage(), ex,\n\t\t\t\t\tinputMessage);\n\t\t}\n\t}\n\n\t@Override\n\tprotected void writeInternal(OidcProviderConfiguration providerConfiguration, HttpOutputMessage outputMessage)\n\t\t\tthrows HttpMessageNotWritableException {\n\t\ttry {\n\t\t\tMap<String, Object> providerConfigurationResponseParameters = this.providerConfigurationParametersConverter\n\t\t\t\t.convert(providerConfiguration);\n\t\t\tthis.jsonMessageConverter.write(providerConfigurationResponseParameters, 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 Provider Configuration: \" + ex.getMessage(), ex);\n\t\t}\n\t}\n\n\t/**\n\t * Sets the {@link Converter} used for converting the OpenID Provider Configuration\n\t * parameters to an {@link OidcProviderConfiguration}.\n\t * @param providerConfigurationConverter the {@link Converter} used for converting to\n\t * an {@link OidcProviderConfiguration}\n\t */\n\tpublic final void setProviderConfigurationConverter(\n\t\t\tConverter<Map<String, Object>, OidcProviderConfiguration> providerConfigurationConverter) {\n\t\tAssert.notNull(providerConfigurationConverter, \"providerConfigurationConverter cannot be null\");\n\t\tthis.providerConfigurationConverter = providerConfigurationConverter;\n\t}\n\n\t/**\n\t * Sets the {@link Converter} used for converting the","sourceCodeStart":82,"sourceCodeEnd":118,"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/OidcProviderConfigurationHttpMessageConverter.java#L82-L118","documentation":"This HttpMessageNotWritableException is thrown by OidcProviderConfigurationHttpMessageConverter.writeInternal when converting the OpenID Provider Configuration to parameters or serializing them to JSON fails. It wraps the underlying exception's message, so the root cause (e.g. JSON conversion failure) is appended. The library treats any failure to render the discovery document as a non-writable response.","triggerScenarios":"The configured providerConfigurationParametersConverter throws during convert(), or the injected jsonMessageConverter fails to write the Map<String,Object> parameters as JSON to the HTTP output message.","commonSituations":"A custom HttpMessageConverter (e.g. Jackson) is misconfigured or missing from the classpath; a custom OidcProviderConfiguration customizer puts a non-serializable value into the configuration map; serialization fails on unusual parameter values.","solutions":["Read the wrapped cause message (ex.getMessage()) to find the actual serialization failure","Check that a JSON converter (Jackson) is on the classpath and usable by the converter","Inspect any custom providerConfiguration consumer for non-JSON-serializable values","Set a working converter via setJsonMessageConverter()/setProviderConfigurationParametersConverter() if customized"],"exampleFix":"// before: customizer adds a non-serializable object\n.customProviderConfiguration(c -> c.put(\"custom\", new Object()))\n// after: use JSON-friendly values only\n.customProviderConfiguration(c -> c.put(\"custom\", \"value\"))","handlingStrategy":"try-catch","validationCode":"// Ensure configuration values are JSON-serializable before conversion\nparameters.forEach((k, v) -> {\n    new ObjectMapper().writeValueAsString(v); // throws if not serializable\n});","typeGuard":"boolean isJsonSerializable(Object v) {\n    try { new ObjectMapper().writeValueAsString(v); return true; }\n    catch (JsonProcessingException e) { return false; }\n}","tryCatchPattern":"try {\n    converter.write(OidcProviderConfiguration.builder().build(), ...);\n} catch (HttpMessageNotWritableException e) {\n    logger.error(\"Provider configuration write failed: {}\", e.getCause(), e);\n}","preventionTips":["Only put JSON-serializable values in provider configuration customizers","Keep Jackson on the classpath and do not override the default converter without need","Smoke-test the discovery endpoint (.well-known/openid-configuration) at startup"],"tags":["http","json","openid-connect","spring-security"],"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"}