Package com.suse.salt.netapi.parser
Class XorTypeAdapterFactory
- java.lang.Object
-
- com.suse.salt.netapi.parser.XorTypeAdapterFactory
-
- All Implemented Interfaces:
com.google.gson.TypeAdapterFactory
public class XorTypeAdapterFactory extends java.lang.Object implements com.google.gson.TypeAdapterFactory
TypeAdaptorFactory creating TypeAdapters for Xor
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.Pattern
FN_UNAVAILABLE
private static java.util.regex.Pattern
MODULE_NOT_SUPPORTED
-
Constructor Summary
Constructors Constructor Description XorTypeAdapterFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <A> com.google.gson.TypeAdapter<A>
create(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<A> typeToken)
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.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.
-
-
-
Method Detail
-
create
public <A> com.google.gson.TypeAdapter<A> create(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<A> typeToken)
- Specified by:
create
in 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
-
-