Skip to main content

Posts

Showing posts with the label JSON

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 { ...

RestTemplate : How to get response from a server by HTTP GET call

Points To Remember You need to add the following dependency to your project to use Spring Rest Template. compile('org.springframework:spring-web:3.0.2.RELEASE') How to get response from a server by HTTP GET call Following are the methods that can be used to get the response from a url using HTTP GET method. getForObject() This method takes a URL , Response class  (it tells that the response should be bound to this class). RestTemplate restTemplate = new RestTemplate(); String response = restTemplate.getForObject("http://localhost:8080/someUrl",String.class); Following method will make a Http GET call with params. Map<String,String> params = new LinkedHashMap<String, String>(); params.put("userId","1"); RestTemplate restTemplate = new RestTemplate(); String response = restTemplate.getForObject("http://localhost:8080/someUrl",String.class,params); This method does not give the following Http status code for the GET cal...