Json 파싱 중 오류 모음

in #java7 years ago (edited)

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

Sort:  

Congratulations @dongchimi! You received a personal award!

1 Year on Steemit

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @dongchimi! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!