Package kong.unirest.core.json
Class CoreFactory
java.lang.Object
kong.unirest.core.json.CoreFactory
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static JsonEngine
private static final List
<Supplier<JsonEngine>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Automatically find and register a JsonEngine.static JsonEngine
Attempt to find the engine by one of the two strategies 1.static JsonEngine
It will attempt to load the loader by class name from the classloader by known names in order.static JsonEngine
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 instanceprivate static UnirestConfigException
static void
setEngine
(JsonEngine jsonEngine) Sets the locators engine to a specific instance
-
Field Details
-
SERVICE_LOCATORS
-
KNOWN_IMPLEMENTATIONS
-
engine
-
-
Constructor Details
-
CoreFactory
public CoreFactory()
-
-
Method Details
-
autoConfig
public static void autoConfig()Automatically find and register a JsonEngine. This method is called by the static block of this class. -
getCore
Gets the registered instance- Returns:
- the JsonEngine registered with this class
- Throws:
UnirestConfigException
- if there is no known instance
-
setEngine
Sets the locators engine to a specific instance- Parameters:
jsonEngine
- the engine you wish to register
-
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
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
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
-
getException
-