Posts

Showing posts with the label jackson

How to serialize a json containing LAZY associations

How to serialize a json containing LAZY associations I am having an Person entity which has @ManyToOne association with Contact entity with fetch type LAZY. I am using spring-boot to expose REST API. One of my POST call contains nested JSON to save the parent entity Person along with association Contact Person @ManyToOne Contact Person Contact Since Contact fetch type is LAZY, I am encountering into following exception Contact ERROR 17415 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and ...

Spring Boot serialize parameteried type into JSON with type id

Spring Boot serialize parameteried type into JSON with type id Spring Boot sample project: https://github.com/yejianfengblue/spring-boot-jackson-serialize-generic-type I have question in how Spring Boot serializes generic type into JSON with Jackson library. Please see my demo: Fruit is a common interface of Apple and Banana . Fruit Apple Banana BasketController has 3 RESTful API: BasketController getFruitList() List<Fruit> getFruitBasket() FruitBasket List<Fruit> getBasketOfFruit() Basket<Fruit> List<T> In BasketController , I log the JSON string written from Jackson Object Mapper and Object Writer . Please see the actual output in the comment below the log statement. BasketController BasketController.java /** <li>Object<b>Mapper</b>.writeValueAsString, @type is lost due to java type erasure. * <li>Object<b>Writer</b>.writeValueAsString, @type is kept */ @GetMapping(path = "getFruitList") public List<Fruit...

Datetime fields in json

Datetime fields in json How do we store postgres datetime objects in java pojo classes for json objects? I am trying to sort them and want to check if I should be comparing datetime or strings? Date compareTo doesn't work but strings comparTo works fine for datetime objects private Date fieldA; private Date fieldB; fieldA.compareTo(fieldB); What do you mean by Date compareTo doesn't work? It always seems to work for me. Have you got an example of two dates for which it gives an incorrect result? – Dawood ibn Kareem Jul 1 at 19:34 Date compareTo @JEE_program I find that extremely difficult to believe. Is there any possibility you have made a mistake of some kind? – Dawood ibn Kareem Jul 1 at 19:43 ...