Home > Java > javaTutorial > How to get JsonGenerator's settings using Jackson in Java?

How to get JsonGenerator's settings using Jackson in Java?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-09-01 18:53:05
forward
925 people have browsed it

The

How to get JsonGenerators settings using Jackson in Java?

JsonGenerator class can be responsible for writing JSON data to the stream instead of building the object model in memory. The list of settings that can be turned on/off exists in the enumeration JsonGenerator.Feature, which contains the static method values( ) , which returns a An array containing constants of this enumeration type.

Syntax

public static enum JsonGenerator.Feature extends Enum<JsonGenerator.Feature>
Copy after login

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();
   }
}
Copy after login

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
Copy after login

The above is the detailed content of How to get JsonGenerator's settings using Jackson in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template