need to handle trailing tokens

see https://github.com/FasterXML/jackson/discussions/143#discussioncomment-4479800
This commit is contained in:
PJ Fanning 2022-12-22 23:13:57 +01:00 committed by GitHub
parent efad3fe07f
commit 2f5696c863
1 changed files with 5 additions and 1 deletions

View File

@ -1,11 +1,15 @@
package com.baeldung.jsonvalidation;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
public class JacksonValidator {
final ObjectMapper mapper = new ObjectMapper();
final ObjectMapper mapper = JsonMapper.builder()
.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
.build();
public boolean isValid(String json) {
try {