Skip to main content

Posts

Showing posts with the label Jackson

SpringBoot : Read JSON object from POST Request in Filter

Points To Remember Add the following dependency to the gradle project. compile('com.fasterxml.jackson.core:jackson-databind:2.7.1-1') Read JSON in Filter and bind it to POJO class You can read the JSON inside a Filter class in SpringBoot by  Create a BufferedReader object by reading request object. Create an ObjectMapper object. Read JSON from bufferedReader object and bind it to any POJO class. view plain copy to clipboard print ? package  com.ekiras.test;      import  com.fasterxml.jackson.databind.JsonMappingException;   import  com.fasterxml.jackson.databind.ObjectMapper;      import  javax.servlet.*;   import  java.io.BufferedReader;   import  java.io.IOException;      /**    * @author ekansh    * @since 26/3/16    */    public   class  MyFilter  implements  Filter { ...

How to Send Rest Response For Lazy fetched Hibernate Objects with Jackson

How to Send Rest Response For Lazy fetched Hibernate Objects with Jackson Just add the following class to your application and your jackson will be configured to send the JSON response for the LAZY fetched domain objects. You need to add the dependency  compile("com.fasterxml.jackson.datatype:jackson-datatype-hibernate4:2.6.1") @Configuration @EnableWebMvc public class HibernateAwareObjectMapper extends WebMvcConfigurerAdapter { //More configuration.... /* Here we register the Hibernate4Module into an ObjectMapper, then set this custom-configured ObjectMapper * to the MessageConverter and return it to be added to the HttpMessageConverters of our application*/ public MappingJackson2HttpMessageConverter jacksonMessageConverter(){ MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter(); ObjectMapper mapper = new ObjectMapper(); //Registering Hibernate4Module to support lazy objects mapper.r...