ObjectMapper.readTree 잘못된 입력에 IOException가 throw하지 않습니다

PX06 :

나는 잭슨 데이터 바인딩을 사용하고 있습니다 2.9.10. 는 내용의 문서에 따르면 :

파싱 ​​문제 (잘못된 JSON)이 발생하면, JsonParseException가 발생한다

참조 : ObjectMapper.readTree를

나는 다음과 같은 검사를 :

    // Given
    String invalidJson = new POJONode("}{").toString();
    final InputStream mockInputStream = new ByteArrayInputStream(invalidJson.getBytes());

    // When
    myLambda.handleRequest(mockInputStream, mockOutputStream, mockContext);

    // Then
    Expect some stuff to happen in the catch JsonProcessingException bit

그러나 readTree로 변환 TextNode해, 예외를 throw하지 않는 ...

디버그 : 여기에 이미지 설명을 입력

어떻게 ObjectMapper 잘못된 입력을 던져 구성 할 수 있습니다?

마이클 Ziober :

당신이 인쇄 할 때 invalidJson변수는 볼 "}{"실제로 유효한 JSON에 acordding json.org . 당신은 또한 같은 일부 웹 도구를 사용하여 다음 사항을 확인 할 수 있습니다 jsonformatter . 직접 설정하면 파서 예외가 발생합니다 invalidJson이 문자열에 변수를 :

String invalidJson = "}{";

넌 봐야 해:

Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Unexpected close marker '}': expected ']' (for root starting at [Source: (String)"}{"; line: 1, column: 0])
 at [Source: (String)"}{"; line: 1, column: 2]

추천

출처http://43.154.161.224:23101/article/api/json?id=330684&siteId=1