Posts

Showing posts with the label JSON

Jackson Object Mapper to conver String to JsonNode

Following are some of the code snippet for Jackson Object Mapper Convert String to JsonNode Object String data; JsonNode jsonNode = getObjectMapper().readTree(data); Convert an Object to JSON String String jsonString = getObjectMapper().writeValueAsString(object); Convert InputStream to JsonNode Object InputStream inputStream; JsonNode jsonNode = getObjectMapper().readTree(inputStream);

JSON Manipulation in Java

JSON stands for Java Script Object Notation, in which essentially we represent data in name:value pair in a string. Example of JSON strin is as follows {    "lastName":"Smith",    "suffix":"Jr",    "city":"Foster City",    "country":"US",    "postalCode":"94404",    "firstName":"John" } Which represent the Data about a user. JSON is a standard notation to exchange data. To process Json String , like converting from Json String to Java or vice versa we have so many different libraries in Java.One of the Most prominent being Jackson, Bellow are the example or Some Use cases for Handling Json in Java. Converting JSON String to Java Object Using Jackson We can use ObjectMapper to convert a JSON String to java Object. ObjectMapper mapper = new ObjectMapper(); UserInfo userInfoObj = mapper.readValue(JSONStringSrc,  UserInfo.class); Where UserInfo Obje...