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

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

WBOY
Release: 2023-09-12 11:57:02
forward
999 people have browsed it

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

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

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

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!

Related labels:
source:tutorialspoint.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template