prestodb/presto · error · IllegalStateException

Failed to serialize token with claims

Error message

Failed to serialize token with claims

What it means

TokenPairSerializer.serialize failed while encoding the token pair plus its claims as Base64 JSON (JSON encoding error); serialization falls back to failing with this error since the cookie payload cannot be produced.

Source

Thrown at presto-main/src/main/java/com/facebook/presto/server/security/oauth2/TokenPairSerializer.java:88

            LOG.debug("Using plain access token format (no claims available, will need to query on authentication)");
            return TokenPair.accessToken(token);
        }

        @Override
        public String serialize(TokenPair tokenPair)
        {
            // If claims are present, serialize as Base64-encoded JSON with access token and claims
            if (tokenPair.getClaims().isPresent()) {
                try {
                    Map<String, Object> data = new HashMap<>();
                    data.put("accessToken", tokenPair.getAccessToken());
                    data.put("claims", tokenPair.getClaims().get());
                    String json = objectMapper.writeValueAsString(data);
                    // Base64 encode to ensure cookie compatibility
                    return Base64.getEncoder().encodeToString(json.getBytes(UTF_8));
                }
                catch (JsonProcessingException e) {
                    throw new IllegalStateException("Failed to serialize token with claims", e);
                }
            }

            // Fallback: serialize as plain access token (backward compatibility)
            return tokenPair.getAccessToken();
        }
    };

    TokenPair deserialize(String token);

    String serialize(TokenPair tokenPair);

    class TokenPair
    {
        private final String accessToken;
        private final Date expiration;
        private final Optional<String> refreshToken;
        private final Optional<Map<String, Object>> claims;

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Check that claim values are JSON-serializable types
  2. Report as a bug with the claim structure that triggered it
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at presto-main/src/main/java/com/facebook/presto/server/security/oauth2/TokenPairSerializer.java:88 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/8992ce9f5c24088d. Report an issue: GitHub.