{"record":{"id":"81668785318309bd","repo":"hs-web/hsweb-framework","slug":"json-decoding-error-originalmessage","errorCode":null,"errorMessage":"JSON decoding error: ${originalMessage}","messagePattern":"JSON decoding error: (.+?)","errorType":"exception","errorClass":"DecodingException","httpStatus":400,"severity":"error","filePath":"hsweb-starter/src/main/java/org/hswebframework/web/starter/jackson/Jackson2Tokenizer.java","lineNumber":89,"sourceCode":"\t\tthis.parser = parser;\n\t\tthis.deserializationContext = deserializationContext;\n\t\tthis.tokenizeArrayElements = tokenizeArrayElements;\n\t\tthis.tokenBuffer = new TokenBuffer(parser, deserializationContext);\n\t\tthis.inputFeeder = (ByteArrayFeeder) this.parser.getNonBlockingInputFeeder();\n\t}\n\n\n\tprivate List<TokenBuffer> tokenize(DataBuffer dataBuffer) {\n\t\tbyte[] bytes = new byte[dataBuffer.readableByteCount()];\n\t\tdataBuffer.read(bytes);\n\t\tDataBufferUtils.release(dataBuffer);\n\n\t\ttry {\n\t\t\tthis.inputFeeder.feedInput(bytes, 0, bytes.length);\n\t\t\treturn parseTokenBufferFlux();\n\t\t}\n\t\tcatch (JsonProcessingException ex) {\n\t\t\tthrow new DecodingException(\"JSON decoding error: \" + ex.getOriginalMessage(), ex);\n\t\t}\n\t\tcatch (IOException ex) {\n\t\t\tthrow Exceptions.propagate(ex);\n\t\t}\n\t}\n\n\tprivate Flux<TokenBuffer> endOfInput() {\n\t\treturn Flux.defer(() -> {\n\t\t\tthis.inputFeeder.endOfInput();\n\t\t\ttry {\n\t\t\t\treturn Flux.fromIterable(parseTokenBufferFlux());\n\t\t\t}\n\t\t\tcatch (JsonProcessingException ex) {\n\t\t\t\tthrow new DecodingException(\"JSON decoding error: \" + ex.getOriginalMessage(), ex);\n\t\t\t}\n\t\t\tcatch (IOException ex) {\n\t\t\t\tthrow Exceptions.propagate(ex);\n\t\t\t}","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/hs-web/hsweb-framework/blob/b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8/hsweb-starter/src/main/java/org/hswebframework/web/starter/jackson/Jackson2Tokenizer.java#L71-L107","documentation":"Jackson2Tokenizer.tokenize() wraps Jackson's JsonProcessingException into Spring's DecodingException with the original parser message, signalling malformed JSON input while streaming-decoding a byte Flux.","triggerScenarios":"Feeding invalid JSON bytes (syntax errors, truncated stream, wrong encoding) into the tokenizer's input feeder; parseTokenBufferFlux encounters a token Jackson cannot parse.","commonSituations":"Client sends malformed request bodies to reactive endpoints expecting JSON; truncated upload; charset mismatch (UTF-8 BOM or invalid bytes); sending form-encoded data to a JSON decoder.","solutions":["Validate/fix the JSON payload sent by the client","Ensure Content-Type is application/json and encoding is UTF-8","Log the full DecodingException cause for the exact parse position","Test the payload with a strict JSON parser to locate the syntax error"],"exampleFix":"// before\ncurl -X POST -d 'name=abc' /api/items\n// after\ncurl -X POST -H 'Content-Type: application/json' -d '{\"name\":\"abc\"}' /api/items","handlingStrategy":"try-catch","validationCode":"try (JsonParser p = new JsonFactory().createParser(bytes)) { while (p.nextToken() != null) {} } catch (JsonProcessingException e) { /* invalid */ }","typeGuard":"static boolean isValidJson(byte[] bytes) {\n    try { new JsonFactory().createParser(bytes).readValueAsTree(); return true; }\n    catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n    return tokenizer.tokenize(buffer);\n} catch (DecodingException e) {\n    log.warn(\"malformed JSON: {}\", e.getOriginalMessage());\n    return Mono.error(ResponseStatusException(HttpStatus.BAD_REQUEST, \"Malformed JSON\", e));\n}","preventionTips":["Send valid UTF-8 JSON with Content-Type application/json","Validate payloads client-side before sending","Map DecodingException to HTTP 400 in reactive handlers","Test with strict JSON validators in CI"],"tags":["json","reactive","decoding"],"backgroundTag":"json-decode-failed","analyzedSha":"b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8","analyzedAt":"2026-09-13T09:05:02.172Z","contentChangedAt":"2026-09-13T09:05:02.172Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}