- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the JsonGenerator settings using Jackson in Java?
The JsonGenerator class can be responsible for writing JSON data as a stream instead of constructing an Object Model in memory. The list of settings that can be turned on/off is present in an enum JsonGenerator.Feature, it contains static method values() that returns an array containing the constants of this enum type.
Syntax
public static enum JsonGenerator.Feature extends Enum<JsonGenerator.Feature>
Example
import java.io.*; import com.fasterxml.jackson.core.*; public class JsonGeneratorSettingsTest { public static void main(String[] args) throws IOException { StringWriter writer = new StringWriter(); JsonFactory jsonFactory = new JsonFactory(); JsonGenerator jsonGenerator = jsonFactory.createGenerator(writer); 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 ESCAPE_NON_ASCII:false WRITE_NUMBERS_AS_STRINGS:false WRITE_BIGDECIMAL_AS_PLAIN:false STRICT_DUPLICATE_DETECTION:false IGNORE_UNKNOWN:false
Advertisements