동치미 avatar

Json 파싱 중 오류 모음

dongchimi

Published: 21 Jan 2018 › Updated: 21 Jan 2018Json 파싱 중 오류 모음

Json 파싱 중 오류 모음

com.fasterxml.jackson.databind.JsonMappingException: Illegal unquoted character ((CTRL-CHAR, code 9)):

-> 해결책
objectMapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true)
추가.

참고 url : https://stackoverflow.com/questions/31537153/jsonparseexception-illegal-unquoted-character-ctrl-char-code-10

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "stockStatus" (class xxx.xxxx.xxx.xxx.xxx.xxx.XXXX), not marked as ignorable

해결책
매핑 클래스 맨 위에
@JsonIgnoreProperties(ignoreUnknown = true)
추가

참고 : https://stackoverflow.com/questions/4486787/jackson-with-json-unrecognized-field-not-marked-as-ignorable

No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.bubu.booksroom.app.utility.response.ApiResponse["data"]->org.bubu.booksroom.provider.entity.Book_$$jvst6d6_8["tags"]->java.util.ArrayList[0]->org.bubu.booksroom.provider.entity.Tag$$_jvst6d6_1["handler"])

jpa를 사용할때 lazy 로딩시 생성되는 handler 가 json 변환시 오류를 발생시킴.

해결책
hibernate 버전에 맞게 pom.xml 에 jackson-datatype-hibernate4 를 추가함.

그리고, 아래와 같이 모듈을 추가 함.

ObjectMapper mapper = new ObjectMapper();
// for Hibernate 4.x:
mapper.registerModule(new Hibernate4Module());

하여 MappingJackson2HttpMessageConverter를 생성하도록 함.
-> 추가수정
위 처럼 하니 일부 메소드 가 사라짐..
3.1 객체 마다 @JsonIgnoreProperties(value={"hibernateLazyInitializer", "handler"}) 를 추가 하던지
3.2 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); 를 추가 함.

참고 url : https://github.com/FasterXML/jackson-datatype-hibernate

Leave Json 파싱 중 오류 모음 to:

Written by

개발자

Read more #java posts


Best Posts From 동치미

We have not curated any of dongchimi's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From 동치미