apolloconfig/apollo · error · RuntimeException

Spring-session JSON deserializing error, This is usually cau

Error message

Spring-session JSON deserializing error, This is usually caused by the system upgrade, please clear the browser cookies and try again.

What it means

Thrown by the JDBC Spring-session converter in the reverse direction (byte[] -> Object) when objectMapper.readValue(source, Object.class) fails. The stored bytes no longer deserialize into a Java object, so the session cannot be restored and the request is rejected (HTTP 500). Like its serialize counterpart, the message attributes the cause to a system upgrade that changed the serialized class shape.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/SpringSessionConfig.java:61

  @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")
  @ConditionalOnProperty(prefix = "spring.session", name = "store-type", havingValue = "redis")
  public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
    return new GenericJackson2JsonRedisSerializer(objectMapper());
  }

  /**
   * Customized {@link ObjectMapper} to add mix-in for class that doesn't have default constructors
   *
   * @return the {@link ObjectMapper} to use
   */

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Clear the affected browser cookies and the matching SPRING_SESSION rows, then authenticate fresh so a new session is written.
  2. Check portal logs for the wrapped IOException / InvalidFormatException to learn which attribute and field fail to deserialize.
  3. If you intentionally changed session attribute classes, flush all sessions in the DB after deploy.
  4. Keep the ObjectMapper returned by SpringSessionConfig.objectMapper() stable across releases (same default typing, same mix-ins).

Example fix

// before: stored session has a class that no longer exists -> readValue throws
// (no code change fixes a corrupted row; you must drop it)

// after: on upgrade, purge stale sessions, then users re-login
DELETE FROM SPRING_SESSION WHERE CREATION_TIME < <upgrade_time>;
Defensive patterns

Strategy: retry

Try / catch

// A stale/corrupted session row usually recovers once the session is recreated.
try {
  return portal.withSession(storedSession).call();
} catch (HttpServerErrorException e) {
  if (e.getResponseBodyAsString().contains("Spring-session JSON deserializing error")) {
    clearPortalCookies();          // discard JSESSIONID
    return portal.freshLogin().call();   // retry once with a clean session
  }
  throw e;
}

Prevention

When it happens

Trigger: A returning portal user whose session row was written by an older portal version (or a different ObjectMapper config) issues a request that needs to read the session, while spring.session.store-type=jdbc and the stored JSON no longer matches the current class structure.

Common situations: Portal upgraded across versions; session DB restored from a backup taken under another build; class refactored/renamed/moved package without a @JsonTypeInfo polymorphic mapping or default typing.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/ed49a275262bfbdd. Report an issue: GitHub.