Module bus.extra

Class JsonFactory

java.lang.Object
org.miaixz.bus.extra.json.JsonFactory

public class JsonFactory extends Object
Factory for creating JSON provider instances. This factory automatically detects the JSON library introduced by the user (e.g., Jackson, Gson, Fastjson) and creates a corresponding JSON parser.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • JsonFactory

      public JsonFactory()
  • Method Details

    • get

      public static JsonProvider get()
      Retrieves the singleton instance of JsonProvider. The provider is created based on the first available JSON library found on the classpath via SPI.
      Returns:
      The singleton JsonProvider instance.
    • create

      public static JsonProvider create()
      Creates a new instance of JsonProvider based on the JSON engine JARs available on the classpath. It is recommended to use the singleton instance provided by get() for better performance, as this method creates a new engine instance on each call.
      Returns:
      A new JsonProvider instance.
      Throws:
      org.miaixz.bus.core.lang.exception.InternalException - if no JSON library (e.g., Jackson, Gson, Fastjson) is found on the classpath.