{"record":{"id":"b4c4ef7ee08737d5","repo":"jwtk/jjwt","slug":"unable-to-deserialize-t-getmessage","errorCode":null,"errorMessage":"Unable to deserialize: ${t.getMessage()}","messagePattern":"Unable to deserialize: (.+?)","errorType":"exception","errorClass":"DeserializationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/jsonwebtoken/io/AbstractDeserializer.java","lineNumber":72,"sourceCode":"        InputStream in = new ByteArrayInputStream(bytes);\n        Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);\n        return deserialize(reader);\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public final T deserialize(Reader reader) throws DeserializationException {\n        Assert.notNull(reader, \"Reader argument cannot be null.\");\n        try {\n            return doDeserialize(reader);\n        } catch (Throwable t) {\n            if (t instanceof DeserializationException) {\n                throw (DeserializationException) t;\n            }\n            String msg = \"Unable to deserialize: \" + t.getMessage();\n            throw new DeserializationException(msg, t);\n        }\n    }\n\n    /**\n     * Reads the specified character stream and returns the corresponding Java object.\n     *\n     * @param reader the reader to use to read the character stream\n     * @return the deserialized Java object\n     * @throws Exception if there is a problem reading the stream or creating the expected Java object\n     */\n    protected abstract T doDeserialize(Reader reader) throws Exception;\n}\n","sourceCodeStart":54,"sourceCodeEnd":85,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/api/src/main/java/io/jsonwebtoken/io/AbstractDeserializer.java#L54-L85","documentation":"io.jsonwebtoken (JJWT) wraps any unexpected Throwable thrown while deserializing a byte/char stream back into a Java object into a DeserializationException. This wrapper is produced by AbstractDeserializer.deserialize when doDeserialize throws something that is not already a DeserializationException (e.g. a RuntimeException from the underlying parser). The original cause is preserved via the cause chain, so inspect getCause() for the real problem.","triggerScenarios":"Calling any JJWT API that must deserialize a payload or claim map (e.g. Jwts.parser().parseClaimsJws(...) with a serialized body, or a custom Serializer/Deserializer implementation whose doDeserialize throws an undeclared exception such as Jackson's JsonParseException, ClassNotFoundException, or a NullPointerException).","commonSituations":"Passing truncated, corrupted, or non-JSON base64url payload text to the parser; a classpath mismatch where the Jackson/Gson runtime is a different version than JJWT expects; deserializing a payload into a custom type whose class is missing at runtime; a custom Deserializer that throws raw exceptions instead of DeserializationException.","solutions":["Inspect the exception's getCause() to find the underlying parser error and fix that root cause first","Verify the token/payload string is valid, complete JSON (not truncated, not HTML, no whitespace corruption from URL handling)","Ensure a supported JSON runtime (Jackson or Gson) is on the classpath at a version compatible with your JJWT release","If you implemented a custom Deserializer, wrap parser failures in DeserializationException inside doDeserialize so the original error type is propagated"],"exampleFix":"// before\nClaims claims = Jwts.parserBuilder().build()\n    .parseClaimsJws(corruptedToken).getBody(); // Unable to deserialize: ...\n\n// after\ntry {\n    Claims claims = Jwts.parserBuilder().build()\n        .parseClaimsJws(token.trim()).getBody();\n} catch (DeserializationException e) {\n    log.error(\"Bad token payload: {}\", e.getCause()); // inspect root cause\n}","handlingStrategy":"try-catch","validationCode":"// Java: sanity-check the token text before parsing\nboolean isPlausibleJwt(String token) {\n    return token != null && token.chars().filter(c -> c == '.').count() == 2\n        && !token.isBlank();\n}","typeGuard":"boolean isDeserializationSafe(java.io.Reader r) {\n    return r != null; // content validity is delegated to the parser; guard nulls and catch DeserializationException\n}","tryCatchPattern":"try {\n    Claims claims = Jwts.parserBuilder().build().parseClaimsJws(token).getBody();\n} catch (DeserializationException e) {\n    Throwable root = e.getCause();\n    // handle malformed payload; log root cause\n}","preventionTips":["Always catch DeserializationException around parse calls and inspect getCause()","Validate tokens are complete, unmodified JWTs (three dot-separated base64url segments) before parsing","Trim and denormalize token strings (remove whitespace/newlines from copy-paste or storage wrapping)","Keep your JSON runtime (Jackson/Gson) at a version compatible with your JJWT release","Return DeserializationException from any custom Deserializer's doDeserialize"],"tags":["deserialization","json","jwt"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}