Class XorTypeAdapterFactory

java.lang.Object
com.suse.salt.netapi.parser.XorTypeAdapterFactory
All Implemented Interfaces:
com.google.gson.TypeAdapterFactory

public class XorTypeAdapterFactory extends Object implements com.google.gson.TypeAdapterFactory
TypeAdaptorFactory creating TypeAdapters for Xor
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Pattern
     
    private static final Pattern
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FN_UNAVAILABLE

      private static final Pattern FN_UNAVAILABLE
    • MODULE_NOT_SUPPORTED

      private static final Pattern 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:
      create in interface com.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 Xor
      R - the generic type for the right side of the Xor
      Parameters:
      leftAdapter - the left adapter
      rightAdapter - 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