{"record":{"id":"1c2316f5fec5ecfd","repo":"jwtk/jjwt","slug":"unable-to-encode-input-e-getmessage","errorCode":null,"errorMessage":"Unable to encode input: ${e.getMessage()}","messagePattern":"Unable to encode input: (.+?)","errorType":"exception","errorClass":"EncodingException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/jsonwebtoken/io/ExceptionPropagatingEncoder.java","lineNumber":57,"sourceCode":"\n    /**\n     * Encoded the specified  data, delegating to the wrapped Encoder, wrapping any\n     * non-{@link EncodingException} as an {@code EncodingException}.\n     *\n     * @param t the data to encode\n     * @return the encoded data\n     * @throws EncodingException if there is an unexpected problem during encoding.\n     */\n    @Override\n    public R encode(T t) throws EncodingException {\n        Assert.notNull(t, \"Encode argument cannot be null.\");\n        try {\n            return this.encoder.encode(t);\n        } catch (EncodingException e) {\n            throw e; //propagate\n        } catch (Exception e) {\n            String msg = \"Unable to encode input: \" + e.getMessage();\n            throw new EncodingException(msg, e);\n        }\n    }\n}\n","sourceCodeStart":39,"sourceCodeEnd":61,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/api/src/main/java/io/jsonwebtoken/io/ExceptionPropagatingEncoder.java#L39-L61","documentation":"ExceptionPropagatingEncoder adapts any Encoder implementation to JJWT's Encoder contract. Its encode method rethrows EncodingException unchanged, but if the delegate encoder throws any other Exception (e.g. IOException writing to a stream), it wraps it in an EncodingException with 'Unable to encode input: ...'. The original exception remains available via getCause().","triggerScenarios":"Any JJWT operation that encodes data (JwtBuilder.compact() encoding header/payload/signature, key or byte encoding via Encoders/Encoder-based APIs) where the underlying encoder throws a non-EncodingException — a raw IOException, RuntimeException, or a custom encoder's unexpected failure.","commonSituations":"A custom Encoder writing to a closed or failing stream (IOException); passing null or an unsupported input type to an encoder that does not guard against it; third-party serialization inside a custom encoder throwing unchecked exceptions; version mismatches between JJWT modules causing unexpected encoder behavior.","solutions":["Inspect getCause() for the delegate encoder's real failure and fix that root cause","Check that the input to encode is non-null and of the expected type for the encoder","If you implemented a custom Encoder, catch internal failures and throw EncodingException from encode() so they propagate without wrapping","Use the built-in Encoders (Base64/Base64Url) or verify your encoder setup and JJWT module versions are consistent"],"exampleFix":"// before\npublic byte[] doEncode(Object o) throws IOException {\n    return mapper.writeValueAsBytes(o); // raw exception -> Unable to encode input\n}\n\n// after\npublic byte[] doEncode(Object o) {\n    try {\n        return mapper.writeValueAsBytes(o);\n    } catch (JsonProcessingException e) {\n        throw new EncodingException(\"Unable to encode object\", e);\n    }\n}","handlingStrategy":"try-catch","validationCode":"// Java: guard input before encoding\nboolean isEncodableInput(Object in) {\n    return in != null && !(in instanceof String s && s.isEmpty())\n        && !(in instanceof byte[] b && b.length == 0);\n}","typeGuard":"boolean isEncoderInput(Object in) {\n    return in instanceof String || in instanceof byte[];\n}","tryCatchPattern":"try {\n    String token = Jwts.builder().setClaims(claims).signWith(key).compact();\n} catch (EncodingException e) {\n    Throwable root = e.getCause();\n    // non-null cause = delegate encoder threw an unexpected exception\n}","preventionTips":["Throw EncodingException (not raw IOException/RuntimeException) from custom Encoder implementations","Null/empty-check data before encoding; ensure streams the encoder writes to are open and healthy","Use built-in Encoders (Base64/Base64Url) when possible instead of bespoke encoders","Keep JJWT module versions consistent on the classpath","Treat 'Unable to encode input' as a wrapper: always examine getCause()"],"tags":["encoding","serialization","jwt"],"backgroundTag":"json-serialization-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"}