This post explains marshalling a java object to json format and storing it to a file. This can be achieved with the help of ObjectMapper provided by jackson databind package. To explain with an example we will use the below pojo objects User public class User { private Name name; private String ssn; private String…… Continue reading Marshaling Java Object
Category: JSON
Retrieving JsonParser Settings
This post explains how to get json parser default settings. import java.io.File; import java.io.IOException; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser.Feature; public class ProcessingDemo2 { public static void main(String[] args) throws JsonParseException, IOException { File file = new File(“jsondata.json”); JsonFactory jsonFactory = new JsonFactory(); JsonParser jsonParser = jsonFactory.createParser(file); for(Feature feature : Feature.values()) { System.out.println(feature.name()…… Continue reading Retrieving JsonParser Settings
Streaming two json files in an order using JsonParserSequence
This post explains how to stream two files in a particular order Main Class import java.io.File; import java.io.IOException; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.util.JsonParserSequence; public class ProcessingDemo3 { public static void main(String[] args) throws JsonParseException, IOException { File file1 = new File(“jsondata.json”); File file2 = new File(“jsondata1.json”); JsonFactory jsonFactory = new…… Continue reading Streaming two json files in an order using JsonParserSequence
Reading JSON in a streaming way
This post explain how to stream a json file. We need to create an instance of JsonFactory, as shown below JsonFactory jsonFactory = new JsonFactory(); by which we can create a parser instance (i.e., JsonParser) to read the json file, as shown below JsonParser jsonParser = jsonFactory.createParser(file); Each element whether start and end of the…… Continue reading Reading JSON in a streaming way