Package kong.unirest.core.json
Class CoreFactory
- java.lang.Object
-
- kong.unirest.core.json.CoreFactory
-
public class CoreFactory extends Object
The CoreFactory is a service locator for JsonEngines Because core does not have a dependency on the various Json implementations this class automatically finds and holds on to a implementation. It will look in the following places in this order: 1. use the java.util.ServiceLoader to load a class by looking for a meta config file in the resources. They should exist at META-INF.services/kong.unirest.core.json.JsonEngine The ServiceLoader will use the first one it finds. see https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html 2. It will attempt to load the loader by class name from the classloader by known names in order. These are: 1. kong.unirest.jackson.JacksonEngine 2. kong.unirest.gson.GsonEngine 3. Clients may set a engine with the setEngine method
-
-
Constructor Summary
Constructors Constructor Description CoreFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
autoConfig()
Automatically find and register a JsonEngine.static JsonEngine
findEngine()
Attempt to find the engine by one of the two strategies 1.static JsonEngine
findEngineWithClassLoader()
It will attempt to load the loader by class name from the classloader by known names in order.static JsonEngine
findEngineWithServiceLocator()
Finds an engine with the ServiceLoader uses the java.util.ServiceLoader to load a class by looking for a meta config file in the resources.static JsonEngine
getCore()
Gets the registered instancestatic void
setEngine(JsonEngine jsonEngine)
Sets the locators engine to a specific instance
-
-
-
Method Detail
-
autoConfig
public static void autoConfig()
Automatically find and register a JsonEngine. This method is called by the static block of this class.
-
getCore
public static JsonEngine getCore()
Gets the registered instance- Returns:
- the JsonEngine registered with this class
- Throws:
UnirestConfigException
- if there is no known instance
-
setEngine
public static void setEngine(JsonEngine jsonEngine)
Sets the locators engine to a specific instance- Parameters:
jsonEngine
- the engine you wish to register
-
findEngine
public static JsonEngine findEngine()
Attempt to find the engine by one of the two strategies 1. use the java.util.ServiceLoader to load a class by looking for a meta config file in the resources. They should exist at META-INF.services/kong.unirest.core.json.JsonEngine The ServiceLoader will use the first one it finds. see https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html 2. It will attempt to load the loader by class name from the classloader by known names in order. These are: 1. kong.unirest.jackson.JacksonEngine 2. kong.unirest.gson.GsonEngine- Returns:
- the first JsonEngine it finds
-
findEngineWithServiceLocator
public static JsonEngine findEngineWithServiceLocator()
Finds an engine with the ServiceLoader uses the java.util.ServiceLoader to load a class by looking for a meta config file in the resources. They should exist at META-INF.services/kong.unirest.core.json.JsonEngine The ServiceLoader will use the first one it finds. see https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html- Returns:
- the first JsonEngine it finds
-
findEngineWithClassLoader
public static JsonEngine findEngineWithClassLoader()
It will attempt to load the loader by class name from the classloader by known names in order. These are: 1. kong.unirest.jackson.JacksonEngine 2. kong.unirest.gson.GsonEngine- Returns:
- the first JsonEngine it finds
-
-