Package com.alibaba.fastjson2
Class JSONFactory
java.lang.Object
com.alibaba.fastjson2.JSONFactory
JSONFactory is the core factory class for creating JSON readers and writers,
as well as managing global configuration for fastjson2.
- Since:
- 2.0.59
- Author:
- wenshao
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic interface -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic JSONReader.ContextCreates a new JSON reader context with default settings.static JSONReader.ContextcreateReadContext(long features) Creates a new JSON reader context with the specified features.static JSONReader.ContextcreateReadContext(Filter filter, JSONReader.Feature... features) static JSONReader.ContextcreateReadContext(JSONReader.Feature... features) Creates a new JSON reader context with the specified features.static JSONReader.ContextcreateReadContext(ObjectReaderProvider provider, JSONReader.Feature... features) static JSONReader.ContextcreateReadContext(SymbolTable symbolTable) static JSONReader.ContextcreateReadContext(SymbolTable symbolTable, JSONReader.Feature... features) static JSONReader.ContextcreateReadContext(Supplier<Map> objectSupplier, JSONReader.Feature... features) static JSONReader.ContextcreateReadContext(Supplier<Map> objectSupplier, Supplier<List> arraySupplier, JSONReader.Feature... features) static JSONWriter.ContextCreates a new JSON writer context with default settings.static JSONWriter.ContextcreateWriteContext(JSONWriter.Feature... features) Creates a new JSON writer context with the specified features.static JSONWriter.ContextcreateWriteContext(ObjectWriterProvider provider, JSONWriter.Feature... features) Creates a new JSON writer context with the specified provider and features.static ObjectReaderCreatorGets the object reader creator for the current thread context.static ObjectWriterCreatorGets the object writer creator for the current thread context.Gets the default array supplier used when creating JSON arrays.static JSONFactory.JSONPathCompilerGets the default JSONPath compiler.static intstatic ObjectReaderProviderGets the default object reader provider.Gets the default object supplier used when creating JSON objects.static ObjectWriterProviderGets the default object writer provider.static longGets the default reader features.static StringGets the default reader format string.static ZoneIdGets the default reader zone ID.static longGets the default writer features.static StringGets the default writer format string.static ZoneIdGets the default writer zone ID.static ObjectReadergetObjectReader(Type type, long features) static ObjectWritergetObjectWriter(Type type, long features) static StringgetProperty(String key) static booleanChecks if transient fields are skipped by default.static booleanChecks if the default writer uses alphabetic ordering.static booleanChecks if array mapping is disabled.static booleanChecks if auto type support is disabled.static booleanChecks if JSONB format is disabled.static booleanChecks if reference detection is disabled.static booleanChecks if smart matching is disabled.static booleanstatic booleanstatic booleanstatic voidSets the JSONPath compiler for the current thread context.static voidSets the object reader provider for the current thread context.static voidSets the object reader creator for the current thread context.static voidSets the object writer creator for the current thread context.static voidsetDefaultArraySupplier(Supplier<List> arraySupplier) Sets the default array supplier used when creating JSON arrays.static voidsetDefaultMaxLevel(int maxLevel) static voidsetDefaultObjectSupplier(Supplier<Map> objectSupplier) Sets the default object supplier used when creating JSON objects.static voidsetDefaultSkipTransient(boolean skipTransient) Sets whether transient fields should be skipped by default.static voidsetDefaultWriterAlphabetic(boolean defaultWriterAlphabetic) Sets whether the default writer should use alphabetic ordering.static voidsetDisableArrayMapping(boolean disableArrayMapping) Sets whether array mapping should be disabled.static voidsetDisableAutoType(boolean disableAutoType) Sets whether auto type support should be disabled.static voidsetDisableJSONB(boolean disableJSONB) Sets whether JSONB format should be disabled.static voidsetDisableReferenceDetect(boolean disableReferenceDetect) Sets whether reference detection should be disabled.static voidsetDisableSmartMatch(boolean disableSmartMatch) Sets whether smart matching should be disabled.static voidsetJSONFieldDefaultValueCompatMode(boolean compatMode) static voidsetUseGsonAnnotation(boolean useGsonAnnotation) static voidsetUseJacksonAnnotation(boolean useJacksonAnnotation)
-
Field Details
-
CREATOR
-
PROPERTY_DENY_PROPERTY
- See Also:
-
PROPERTY_AUTO_TYPE_ACCEPT
- See Also:
-
PROPERTY_AUTO_TYPE_HANDLER
- See Also:
-
PROPERTY_AUTO_TYPE_BEFORE_HANDLER
- See Also:
-
-
Constructor Details
-
JSONFactory
public JSONFactory()
-
-
Method Details
-
getProperty
-
isUseJacksonAnnotation
public static boolean isUseJacksonAnnotation() -
isUseGsonAnnotation
public static boolean isUseGsonAnnotation() -
setUseJacksonAnnotation
public static void setUseJacksonAnnotation(boolean useJacksonAnnotation) -
setUseGsonAnnotation
public static void setUseGsonAnnotation(boolean useGsonAnnotation) -
isJSONFieldDefaultValueCompatMode
public static boolean isJSONFieldDefaultValueCompatMode() -
setJSONFieldDefaultValueCompatMode
public static void setJSONFieldDefaultValueCompatMode(boolean compatMode) -
getDefaultMaxLevel
public static int getDefaultMaxLevel() -
setDefaultMaxLevel
public static void setDefaultMaxLevel(int maxLevel) -
setDefaultObjectSupplier
Sets the default object supplier used when creating JSON objects.- Parameters:
objectSupplier- the supplier for creating Map instances- Since:
- 2.0.15
-
setDefaultArraySupplier
Sets the default array supplier used when creating JSON arrays.- Parameters:
arraySupplier- the supplier for creating List instances- Since:
- 2.0.15
-
getDefaultObjectSupplier
Gets the default object supplier used when creating JSON objects.- Returns:
- the supplier for creating Map instances
-
getDefaultArraySupplier
Gets the default array supplier used when creating JSON arrays.- Returns:
- the supplier for creating List instances
-
createWriteContext
Creates a new JSON writer context with default settings.- Returns:
- a new JSONWriter.Context instance
-
createWriteContext
public static JSONWriter.Context createWriteContext(ObjectWriterProvider provider, JSONWriter.Feature... features) Creates a new JSON writer context with the specified provider and features.- Parameters:
provider- the object writer providerfeatures- the features to enable- Returns:
- a new JSONWriter.Context instance
-
createWriteContext
Creates a new JSON writer context with the specified features.- Parameters:
features- the features to enable- Returns:
- a new JSONWriter.Context instance
-
createReadContext
Creates a new JSON reader context with default settings.- Returns:
- a new JSONReader.Context instance
-
createReadContext
Creates a new JSON reader context with the specified features.- Parameters:
features- the features to enable- Returns:
- a new JSONReader.Context instance
-
createReadContext
Creates a new JSON reader context with the specified features.- Parameters:
features- the features to enable- Returns:
- a new JSONReader.Context instance
-
createReadContext
-
createReadContext
public static JSONReader.Context createReadContext(ObjectReaderProvider provider, JSONReader.Feature... features) -
createReadContext
-
createReadContext
public static JSONReader.Context createReadContext(SymbolTable symbolTable, JSONReader.Feature... features) -
createReadContext
public static JSONReader.Context createReadContext(Supplier<Map> objectSupplier, JSONReader.Feature... features) -
createReadContext
public static JSONReader.Context createReadContext(Supplier<Map> objectSupplier, Supplier<List> arraySupplier, JSONReader.Feature... features) -
getObjectReader
-
getObjectWriter
-
getDefaultObjectWriterProvider
Gets the default object writer provider.- Returns:
- the default ObjectWriterProvider instance
-
getDefaultObjectReaderProvider
Gets the default object reader provider.- Returns:
- the default ObjectReaderProvider instance
-
getDefaultJSONPathCompiler
Gets the default JSONPath compiler.- Returns:
- the default JSONPathCompiler instance
-
setContextReaderCreator
Sets the object reader creator for the current thread context.- Parameters:
creator- the ObjectReaderCreator to set
-
setContextObjectReaderProvider
Sets the object reader provider for the current thread context.- Parameters:
creator- the ObjectReaderProvider to set
-
getContextReaderCreator
Gets the object reader creator for the current thread context.- Returns:
- the ObjectReaderCreator for the current thread, or null if not set
-
setContextJSONPathCompiler
Sets the JSONPath compiler for the current thread context.- Parameters:
compiler- the JSONPathCompiler to set
-
setContextWriterCreator
Sets the object writer creator for the current thread context.- Parameters:
creator- the ObjectWriterCreator to set
-
getContextWriterCreator
Gets the object writer creator for the current thread context.- Returns:
- the ObjectWriterCreator for the current thread, or null if not set
-
getDefaultReaderFeatures
public static long getDefaultReaderFeatures()Gets the default reader features.- Returns:
- the default reader features as a long value
-
getDefaultReaderZoneId
Gets the default reader zone ID.- Returns:
- the default ZoneId for readers
-
getDefaultReaderFormat
Gets the default reader format string.- Returns:
- the default format string for readers
-
getDefaultWriterFeatures
public static long getDefaultWriterFeatures()Gets the default writer features.- Returns:
- the default writer features as a long value
-
getDefaultWriterZoneId
Gets the default writer zone ID.- Returns:
- the default ZoneId for writers
-
getDefaultWriterFormat
Gets the default writer format string.- Returns:
- the default format string for writers
-
isDefaultWriterAlphabetic
public static boolean isDefaultWriterAlphabetic()Checks if the default writer uses alphabetic ordering.- Returns:
- true if alphabetic ordering is enabled, false otherwise
-
setDefaultWriterAlphabetic
public static void setDefaultWriterAlphabetic(boolean defaultWriterAlphabetic) Sets whether the default writer should use alphabetic ordering.- Parameters:
defaultWriterAlphabetic- true to enable alphabetic ordering, false to disable
-
isDisableReferenceDetect
public static boolean isDisableReferenceDetect()Checks if reference detection is disabled.- Returns:
- true if reference detection is disabled, false otherwise
-
isDisableAutoType
public static boolean isDisableAutoType()Checks if auto type support is disabled.- Returns:
- true if auto type is disabled, false otherwise
-
isDisableJSONB
public static boolean isDisableJSONB()Checks if JSONB format is disabled.- Returns:
- true if JSONB is disabled, false otherwise
-
isDisableArrayMapping
public static boolean isDisableArrayMapping()Checks if array mapping is disabled.- Returns:
- true if array mapping is disabled, false otherwise
-
setDisableReferenceDetect
public static void setDisableReferenceDetect(boolean disableReferenceDetect) Sets whether reference detection should be disabled.- Parameters:
disableReferenceDetect- true to disable reference detection, false to enable
-
setDisableArrayMapping
public static void setDisableArrayMapping(boolean disableArrayMapping) Sets whether array mapping should be disabled.- Parameters:
disableArrayMapping- true to disable array mapping, false to enable
-
setDisableJSONB
public static void setDisableJSONB(boolean disableJSONB) Sets whether JSONB format should be disabled.- Parameters:
disableJSONB- true to disable JSONB, false to enable
-
setDisableAutoType
public static void setDisableAutoType(boolean disableAutoType) Sets whether auto type support should be disabled.- Parameters:
disableAutoType- true to disable auto type, false to enable
-
isDisableSmartMatch
public static boolean isDisableSmartMatch()Checks if smart matching is disabled.- Returns:
- true if smart matching is disabled, false otherwise
-
setDisableSmartMatch
public static void setDisableSmartMatch(boolean disableSmartMatch) Sets whether smart matching should be disabled.- Parameters:
disableSmartMatch- true to disable smart matching, false to enable
-
isDefaultSkipTransient
public static boolean isDefaultSkipTransient()Checks if transient fields are skipped by default.- Returns:
- true if transient fields are skipped, false otherwise
-
setDefaultSkipTransient
public static void setDefaultSkipTransient(boolean skipTransient) Sets whether transient fields should be skipped by default.- Parameters:
skipTransient- true to skip transient fields, false to include them
-