Class 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  
    • 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.
      • Methods inherited from class java.lang.Object

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

      • FN_UNAVAILABLE

        private static final java.util.regex.Pattern FN_UNAVAILABLE
      • MODULE_NOT_SUPPORTED

        private static final java.util.regex.Pattern MODULE_NOT_SUPPORTED
    • Constructor Detail

      • XorTypeAdapterFactory

        public XorTypeAdapterFactory()
    • 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 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