Class JSONFactory

java.lang.Object
com.alibaba.fastjson2.JSONFactory

public final class JSONFactory extends Object
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
  • Field Details

  • Constructor Details

    • JSONFactory

      public JSONFactory()
  • Method Details

    • getProperty

      public static String getProperty(String key)
    • 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

      public static void setDefaultObjectSupplier(Supplier<Map> objectSupplier)
      Sets the default object supplier used when creating JSON objects.
      Parameters:
      objectSupplier - the supplier for creating Map instances
      Since:
      2.0.15
    • setDefaultArraySupplier

      public static void setDefaultArraySupplier(Supplier<List> arraySupplier)
      Sets the default array supplier used when creating JSON arrays.
      Parameters:
      arraySupplier - the supplier for creating List instances
      Since:
      2.0.15
    • getDefaultObjectSupplier

      public static Supplier<Map> getDefaultObjectSupplier()
      Gets the default object supplier used when creating JSON objects.
      Returns:
      the supplier for creating Map instances
    • getDefaultArraySupplier

      public static Supplier<List> getDefaultArraySupplier()
      Gets the default array supplier used when creating JSON arrays.
      Returns:
      the supplier for creating List instances
    • createWriteContext

      public static JSONWriter.Context 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 provider
      features - the features to enable
      Returns:
      a new JSONWriter.Context instance
    • createWriteContext

      public static JSONWriter.Context createWriteContext(JSONWriter.Feature... features)
      Creates a new JSON writer context with the specified features.
      Parameters:
      features - the features to enable
      Returns:
      a new JSONWriter.Context instance
    • createReadContext

      public static JSONReader.Context createReadContext()
      Creates a new JSON reader context with default settings.
      Returns:
      a new JSONReader.Context instance
    • createReadContext

      public static JSONReader.Context createReadContext(long features)
      Creates a new JSON reader context with the specified features.
      Parameters:
      features - the features to enable
      Returns:
      a new JSONReader.Context instance
    • createReadContext

      public static JSONReader.Context createReadContext(JSONReader.Feature... features)
      Creates a new JSON reader context with the specified features.
      Parameters:
      features - the features to enable
      Returns:
      a new JSONReader.Context instance
    • createReadContext

      public static JSONReader.Context createReadContext(Filter filter, JSONReader.Feature... features)
    • createReadContext

      public static JSONReader.Context createReadContext(ObjectReaderProvider provider, JSONReader.Feature... features)
    • createReadContext

      public static JSONReader.Context createReadContext(SymbolTable symbolTable)
    • 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

      public static ObjectReader getObjectReader(Type type, long features)
    • getObjectWriter

      public static ObjectWriter getObjectWriter(Type type, long features)
    • getDefaultObjectWriterProvider

      public static ObjectWriterProvider getDefaultObjectWriterProvider()
      Gets the default object writer provider.
      Returns:
      the default ObjectWriterProvider instance
    • getDefaultObjectReaderProvider

      public static ObjectReaderProvider getDefaultObjectReaderProvider()
      Gets the default object reader provider.
      Returns:
      the default ObjectReaderProvider instance
    • getDefaultJSONPathCompiler

      public static JSONFactory.JSONPathCompiler getDefaultJSONPathCompiler()
      Gets the default JSONPath compiler.
      Returns:
      the default JSONPathCompiler instance
    • setContextReaderCreator

      public static void setContextReaderCreator(ObjectReaderCreator creator)
      Sets the object reader creator for the current thread context.
      Parameters:
      creator - the ObjectReaderCreator to set
    • setContextObjectReaderProvider

      public static void setContextObjectReaderProvider(ObjectReaderProvider creator)
      Sets the object reader provider for the current thread context.
      Parameters:
      creator - the ObjectReaderProvider to set
    • getContextReaderCreator

      public static ObjectReaderCreator getContextReaderCreator()
      Gets the object reader creator for the current thread context.
      Returns:
      the ObjectReaderCreator for the current thread, or null if not set
    • setContextJSONPathCompiler

      public static void setContextJSONPathCompiler(JSONFactory.JSONPathCompiler compiler)
      Sets the JSONPath compiler for the current thread context.
      Parameters:
      compiler - the JSONPathCompiler to set
    • setContextWriterCreator

      public static void setContextWriterCreator(ObjectWriterCreator creator)
      Sets the object writer creator for the current thread context.
      Parameters:
      creator - the ObjectWriterCreator to set
    • getContextWriterCreator

      public static ObjectWriterCreator 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

      public static ZoneId getDefaultReaderZoneId()
      Gets the default reader zone ID.
      Returns:
      the default ZoneId for readers
    • getDefaultReaderFormat

      public static String 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

      public static ZoneId getDefaultWriterZoneId()
      Gets the default writer zone ID.
      Returns:
      the default ZoneId for writers
    • getDefaultWriterFormat

      public static String 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