Handling json deserialization error

This post explains how to handle errors generated while deserializing the json file. This can be achieved by implementing an interface “DeserializationProblemHandler” provided by jackson framework as shown below UnMarshallingErrorHandler package package1; import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler; public class UnMarshallingErrorHandler extends DeserializationProblemHandler { @Override public boolean handleUnknownProperty(DeserializationContext ctxt,…… Continue reading Handling json deserialization error

Getting JsonGenerator settings

This post explains how to get JsonGenerator settings. JsonGenerator class obtained from JsonFactory is responsible for writing json data as a stream instead of constructing an entire object model in memory and then writing to destination. The list of settings that can be turned on or off are present in an enumeration JsonGenerator.Feature. The below…… Continue reading Getting JsonGenerator settings

Getting JsonFactory settings

This post explains how to get JsonFactory settings. The JsonFactory class is thread safe and responsible for creating instances of writer and reader. Creating an instance of JsonFactory is an light weight operation. The list of settings that can be turned on or off are present in an enumeration JsonFactory.Feature. The below code shows how…… Continue reading Getting JsonFactory settings

Writing json data using Jackson JsonGenerator

The below post explains how to write json data to file using JsonGenerator. JsonGenerator writes the data to a file in streaming way, helping the developer using the api to avoid creating an object representation of the data. We can get an instance of JsonGenerator with the help of an instance of JsonFactory as shown…… Continue reading Writing json data using Jackson JsonGenerator

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