Home  >  Article  >  Java  >  How to get JSONParser's default settings using Jackson in Java?

How to get JSONParser's default settings using Jackson in Java?

WBOY
WBOYforward
2023-09-12 11:57:02940browse

How to get JSONParsers default settings using Jackson in Java?

The default settings of all JSON parsers can be represented using the JsonParser.Feature enumeration . JsonParser.Feature.values() will return all features available for JSONParser , but whether a specific parser enables or disables a feature can use JsonParser's isEnabled()Method to determine.

Syntax

public static enum JsonParser.Feature extends Enum<JsonParser.Feature>

Example

import com.fasterxml.jackson.core.*;
import java.io.*;
public class JsonParserSettingsTest {
   public static void main(String[] args) throws IOException {
      String json = "[{\"name\":\"Adithya\", \"age\":\"30\"}," + "{\"name\":\"Ravi\", \"age\":\"35\"}]";
      JsonFactory jsonFactory = new JsonFactory();
      JsonParser jsonParser = jsonFactory.createParser(json);
      for(JsonParser.Feature feature : JsonParser.Feature.values()) {
         System.out.println(feature.name() + ":" + jsonParser.isEnabled(feature));
      }
   }
}

Output

AUTO_CLOSE_SOURCE:true
ALLOW_COMMENTS:false
ALLOW_YAML_COMMENTS:false
ALLOW_UNQUOTED_FIELD_NAMES:false
ALLOW_SINGLE_QUOTES:false
ALLOW_UNQUOTED_CONTROL_CHARS:false
ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER:false
ALLOW_NUMERIC_LEADING_ZEROS:false
ALLOW_NON_NUMERIC_NUMBERS:false
ALLOW_MISSING_VALUES:false
ALLOW_TRAILING_COMMA:false
STRICT_DUPLICATE_DETECTION:false
IGNORE_UNDEFINED:false
INCLUDE_SOURCE_IN_LOCATION:true

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

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete