PX06 :
나는 잭슨 데이터 바인딩을 사용하고 있습니다 2.9.10
. 는 내용의 문서에 따르면 :
파싱 문제 (잘못된 JSON)이 발생하면, JsonParseException가 발생한다
나는 다음과 같은 검사를 :
// 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]