Class XorTypeAdapterFactory
java.lang.Object
com.suse.salt.netapi.parser.XorTypeAdapterFactory
- All Implemented Interfaces:
com.google.gson.TypeAdapterFactory
TypeAdaptorFactory creating TypeAdapters for Xor
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<A> com.google.gson.TypeAdapter<A> create(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<A> typeToken) errorAdapter(com.google.gson.TypeAdapter<R> innerAdapter) Creates a Xor adapter specifically for the case in which the left side is a SaltError.private <L,R> com.google.gson.TypeAdapter <Xor<L, R>> xorAdapter(com.google.gson.TypeAdapter<L> leftAdapter, com.google.gson.TypeAdapter<R> rightAdapter) Creates a generic Xor adapter by combining two other adapters - one for each side of the Xor type.
-
Field Details
-
FN_UNAVAILABLE
-
MODULE_NOT_SUPPORTED
-
-
Constructor Details
-
XorTypeAdapterFactory
public XorTypeAdapterFactory()
-
-
Method Details
-
create
public <A> com.google.gson.TypeAdapter<A> create(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<A> typeToken) - Specified by:
createin interfacecom.google.gson.TypeAdapterFactory
-
xorAdapter
private <L,R> com.google.gson.TypeAdapter<Xor<L,R>> xorAdapter(com.google.gson.TypeAdapter<L> leftAdapter, com.google.gson.TypeAdapter<R> rightAdapter) Creates a generic Xor adapter by combining two other adapters - one for each side of the Xor type. It will first try to parse incoming JSON data as the right type and, if that does not succeed, it will try again with the left type. All exceptions besides the possible parsing Exception of the left type are not caught.- Type Parameters:
L- the generic type for the left side of the XorR- the generic type for the right side of the Xor- Parameters:
leftAdapter- the left adapterrightAdapter- the right adapter- Returns:
- the Xor adapter
-
errorAdapter
private <R> com.google.gson.TypeAdapter<Xor<SaltError, R>> errorAdapter(com.google.gson.TypeAdapter<R> innerAdapter) Creates a Xor adapter specifically for the case in which the left side is a SaltError. This is used to catch any Salt-side or JSON parsing errors.- Type Parameters:
R- the generic type for the right side of the Xor- Parameters:
innerAdapter- the inner adapter- Returns:
- the Xor type adapter
-