Class DescDeserializer<T extends Desc<K,V>,K extends Enum<K>,V extends HasDesc<T>>

java.lang.Object
com.fasterxml.jackson.databind.JsonDeserializer<T>
com.fasterxml.jackson.databind.deser.std.StdDeserializer<T>
net.demilich.metastone.game.cards.desc.DescDeserializer<T,K,V>
Type Parameters:
T -
K -
V -
All Implemented Interfaces:
com.fasterxml.jackson.databind.deser.NullValueProvider, com.fasterxml.jackson.databind.deser.ValueInstantiator.Gettable, Serializable
Direct Known Subclasses:
AuraDescDeserializer, CardCostModifierDescDeserializer, CardSourceDescDeserializer, ConditionDescDeserializer, DynamicDescriptionDeserializer, EntityFilterDescDeserializer, EventTriggerDescDeserializer, SpellDescDeserializer, ValueProviderDescDeserializer

public abstract class DescDeserializer<T extends Desc<K,V>,K extends Enum<K>,V extends HasDesc<T>> extends com.fasterxml.jackson.databind.deser.std.StdDeserializer<T>
A base class for deserializers of the "component" or object types in the Spellsource card JSON. Each type, like Spell, has a corresponding Desc, like SpellDesc, which is deserialized by this class's implementor SpellDescDeserializer. In that class, the #init(SerializationContext) implementation adds the mappings from each enum value of SpellArg to its corresponding ParseValueType.

To help visualize, this means that if <K> is your enum type and <V> is your class deserialize to, you'll have:

For example, for a Spell subclass like DamageSpell, you might see the JSON:

   "spell": {
     "class": "DamageSpell",
     "value": {
       "class": "CurrentTurnValueProvider"
     },
     "target": "ENEMY_CHARACTERS"
   }
 

ParseUtils.parse(JsonNode, ParseValueType, DeserializationContext) knows to turn "spell" into a SpellDesc instance because in some #init(SerializationContext), an arg (like SpellArg.SPELL) is configured to be of type ParseValueType.SPELL.

Then, a field like "class" is known to be the "class arg" and is put with SpellArg.CLASS as the key and a Class instance as a value. For a field like "value", it is turned into UPPER_CASE (so "VALUE") and simply passed to Enum.valueOf(Class, String) to find the corresponding enum constant to use as the key. The init implementation specifies that SpellArg.VALUE is a ParseValueType.VALUE, which is a union of types of integer or a ValueProviderDesc. If it encounters a number, it'll put a number into the desc map. Otherwise, it will decode a ValueProviderDesc using a similar process and actually instantiate it into its concrete type using Desc.create(). That means it will look up the "class" field as a class (in this case, "CurrentTurnValueProvider") and create an instance of it. So all in all, the Java equivalent of deserializing the JSON example above looks like:

   
   SpellDesc desc = new SpellDesc(DamageSpell.class);
   desc.put(SpellArg.TARGET, EntityReference.ENEMY_CHARACTERS);
   ValueProviderDesc valueProviderDesc = new ValueProviderDesc(CurrentTurnValueProvider.class);
   ValueProvider valueProvider = valueProviderDesc.create();
   desc.put(SpellArg.VALUE, valueProvider);
   
 
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected class 
     

    Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonDeserializer

    com.fasterxml.jackson.databind.JsonDeserializer.None
  • Field Summary

    Fields inherited from class com.fasterxml.jackson.databind.deser.std.StdDeserializer

    _valueClass, _valueType, F_MASK_ACCEPT_ARRAYS, F_MASK_INT_COERCIONS
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    DescDeserializer(Class<? extends T> vc)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract T
     
    deserialize(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt)
     
    protected abstract Class<V>
     
    protected abstract Class<K>
     
    abstract void
    Gives the implementing deserializer the opportunity to specify how a key in its enum should be deserialized.
    innerDeserialize(com.fasterxml.jackson.databind.DeserializationContext ctxt, com.fasterxml.jackson.databind.JsonNode node)
     

    Methods inherited from class com.fasterxml.jackson.databind.deser.std.StdDeserializer

    _byteOverflow, _checkBooleanToStringCoercion, _checkCoercionFail, _checkDoubleSpecialValue, _checkFloatSpecialValue, _checkFloatToIntCoercion, _checkFloatToStringCoercion, _checkFromStringCoercion, _checkFromStringCoercion, _checkIntToFloatCoercion, _checkIntToStringCoercion, _checkTextualNull, _checkToStringCoercion, _coerceBooleanFromInt, _coercedTypeDesc, _coerceEmptyString, _coerceIntegral, _coerceNullToken, _coerceTextualNull, _deserializeFromArray, _deserializeFromEmpty, _deserializeFromEmptyString, _deserializeFromString, _deserializeWrappedValue, _failDoubleToIntCoercion, _findCoercionFromBlankString, _findCoercionFromEmptyArray, _findCoercionFromEmptyString, _findNullProvider, _hasTextualNull, _intOverflow, _isBlank, _isEmptyOrTextualNull, _isFalse, _isIntNumber, _isNaN, _isNegInf, _isPosInf, _isTrue, _neitherNull, _nonNullNumber, _parseBoolean, _parseBooleanFromInt, _parseBooleanPrimitive, _parseBooleanPrimitive, _parseBytePrimitive, _parseDate, _parseDate, _parseDateFromArray, _parseDouble, _parseDouble, _parseDoublePrimitive, _parseDoublePrimitive, _parseDoublePrimitive, _parseFloatPrimitive, _parseFloatPrimitive, _parseFloatPrimitive, _parseInteger, _parseInteger, _parseIntPrimitive, _parseIntPrimitive, _parseLong, _parseLong, _parseLongPrimitive, _parseLongPrimitive, _parseShortPrimitive, _parseString, _parseString, _reportFailedNullCoerce, _shortOverflow, _verifyEndArrayForSingle, _verifyNullForPrimitive, _verifyNullForPrimitiveCoercion, _verifyNullForScalarCoercion, _verifyNumberForScalarCoercion, _verifyStringForScalarCoercion, deserializeWithType, findContentNullProvider, findContentNullStyle, findConvertingContentDeserializer, findDeserializer, findFormatFeature, findFormatOverrides, findValueNullProvider, getValueClass, getValueInstantiator, getValueType, getValueType, handledType, handleMissingEndArrayForSingle, handleNestedArrayForSingle, handleUnknownProperty, isDefaultDeserializer, isDefaultKeyDeserializer

    Methods inherited from class com.fasterxml.jackson.databind.JsonDeserializer

    deserialize, deserializeWithType, findBackReference, getAbsentValue, getDelegatee, getEmptyAccessPattern, getEmptyValue, getEmptyValue, getKnownPropertyNames, getNullAccessPattern, getNullValue, getNullValue, getObjectIdReader, isCachable, logicalType, replaceDelegatee, supportsUpdate, unwrappingDeserializer

    Methods inherited from class java.lang.Object

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

    • DescDeserializer

      protected DescDeserializer(Class<? extends T> vc)
  • Method Details

    • createDescInstance

      protected abstract T createDescInstance()
    • init

      public abstract void init(DescDeserializer<T,K,V>.SerializationContext ctx)
      Gives the implementing deserializer the opportunity to specify how a key in its enum should be deserialized.

      Call the DescDeserializer.SerializationContext.add(Enum, ParseValueType) method to specify this mapping.

      Parameters:
      ctx - The serialization context.
    • getAbstractComponentClass

      protected abstract Class<V> getAbstractComponentClass()
    • getEnumType

      protected abstract Class<K> getEnumType()
    • deserialize

      public T deserialize(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt) throws IOException
      Specified by:
      deserialize in class com.fasterxml.jackson.databind.JsonDeserializer<T extends Desc<K,V>>
      Throws:
      IOException
    • innerDeserialize

      public T innerDeserialize(com.fasterxml.jackson.databind.DeserializationContext ctxt, com.fasterxml.jackson.databind.JsonNode node) throws com.fasterxml.jackson.databind.JsonMappingException
      Throws:
      com.fasterxml.jackson.databind.JsonMappingException