apolloconfig/apollo · error · RuntimeException
Spring-session JSON serializing error, This is usually cause
Error message
Spring-session JSON serializing error, This is usually caused by the system upgrade, please clear the browser cookies and try again.
What it means
Thrown inside the JDBC-backed Spring-session converter registered by SpringSessionConfig. The converter calls objectMapper.writeValueAsBytes(source) to turn a session attribute (Object) into a byte[] for the SPRING_SESSION table; if Jackson raises an IOException it is wrapped in this RuntimeException (HTTP 500). The message points at a version upgrade because the most common root cause is an incompatible class shape read back from an older session row.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/SpringSessionConfig.java:51
*
* @author kl (http://kailing.pub)
* @since 2022/7/26
*/
@Configuration
public class SpringSessionConfig implements BeanClassLoaderAware {
private ClassLoader loader;
@Bean("springSessionConversionService")
@ConditionalOnProperty(prefix = "spring.session", name = "store-type", havingValue = "jdbc")
public ConversionService springSessionConversionService() {
GenericConversionService conversionService = new GenericConversionService();
ObjectMapper objectMapper = this.objectMapper();
conversionService.addConverter(Object.class, byte[].class, source -> {
try {
return objectMapper.writeValueAsBytes(source);
} catch (IOException e) {
throw new RuntimeException(
"Spring-session JSON serializing error, This is usually caused by the system upgrade, please clear the browser cookies and try again.",
e);
}
});
conversionService.addConverter(byte[].class, Object.class, source -> {
try {
return objectMapper.readValue(source, Object.class);
} catch (IOException e) {
throw new RuntimeException(
"Spring-session JSON deserializing error, This is usually caused by the system upgrade, please clear the browser cookies and try again.",
e);
}
});
return conversionService;
}
@Bean("springSessionDefaultRedisSerializer")View on GitHub (pinned to d95fc18d11)
Solutions
- Clear browser cookies (or the SPRING_SESSION / SPRING_SESSION_ATTRIBUTES rows for that session id) so the stale attribute is discarded, then log in again.
- Inspect the wrapped IOException in the portal log stack trace to find the exact attribute type that fails serialization.
- If a custom object is the culprit, make it Jackson-serializable (no-arg constructor, or register a mix-in / ObjectMapper config consistent with SpringSessionConfig.objectMapper()).
- During a planned upgrade, flush active sessions on both portal and its session DB to avoid mixing old and new attribute shapes.
Example fix
// before: polymorphic object in session breaks Jackson
session.setAttribute("ctx", someUntypedObject);
// after: store a Jackson-friendly DTO with a no-arg ctor and explicit type
session.setAttribute("ctx", new ContextDTO(someUntypedObject)); Defensive patterns
Strategy: try-catch
Try / catch
// Portal API client: any session-mutating call can 500 with this message on a stale session.
try {
portal.login(credentials);
} catch (HttpServerErrorException e) {
if (e.getResponseBodyAsString().contains("Spring-session JSON serializing error")) {
clearPortalCookies(); // drop the local JSESSIONID
purgeServerSessionRow(); // optional: delete SPRING_SESSION row
portal.login(credentials); // fresh session
} else { throw e; }
} Prevention
- Flush active sessions (portal + session DB) during every portal upgrade.
- Do not place custom non-serializable objects into the HTTP session.
- Keep the ObjectMapper in SpringSessionConfig stable across releases.
- Log and alert on the wrapped IOException to catch the failing attribute early.
When it happens
Trigger: Any portal request that mutates the HTTP session (login, role/permission grant, logout) while spring.session.store-type=jdbc AND a session attribute is a type Jackson cannot serialize (missing no-arg ctor, polymorphic type without @JsonTypeInfo, circular ref).
Common situations: Upgrading Apollo portal across versions where session attribute classes changed package/shape; storing a custom non-serializable object in the session; a corrupted or half-migrated SPRING_SESSION row left from a previous deploy.
Related errors
- Spring-session JSON deserializing error, This is usually cau
- Current user not found
- Portal user session is required
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/912cc4c1805d222e.
Report an issue: GitHub.