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 code shows how to access their values

Main Code


package package6;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;

public class ProcessingDemo6 {
    public static void main(String[] args) throws IOException {
        JsonFactory jsonFactory = new JsonFactory();
        File file = new File("jsondata5.json");
        try(FileWriter fw = new FileWriter(file);) {
            JsonGenerator jsonGenerator = jsonFactory.createGenerator(fw);
            for(JsonGenerator.Feature feature : JsonGenerator.Feature.values()) {
                boolean result = jsonGenerator.isEnabled(feature);
                System.out.println(feature.name() + ":" + result);
            }
            jsonGenerator.close();
        }
    }
}

Output

AUTO_CLOSE_TARGET:true
AUTO_CLOSE_JSON_CONTENT:true
FLUSH_PASSED_TO_STREAM:true
QUOTE_FIELD_NAMES:true
QUOTE_NON_NUMERIC_NUMBERS:true
WRITE_NUMBERS_AS_STRINGS:false
WRITE_BIGDECIMAL_AS_PLAIN:false
ESCAPE_NON_ASCII:false
STRICT_DUPLICATE_DETECTION:false
IGNORE_UNKNOWN:false

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s