Class AbstractMapSchema<K,V>

java.lang.Object
dev.drtheo.autojson.schema.util.AbstractMapSchema<K,V>
Type Parameters:
K - the key type.
V - the value type.
All Implemented Interfaces:
ObjectSchema<Map<K,V>>, Schema<Map<K,V>>
Direct Known Subclasses:
JavaMapSchema, String2ObjectMapSchema

public abstract class AbstractMapSchema<K,V> extends Object implements ObjectSchema<Map<K,V>>
The base map schema.
Implementation Note:
the key type should have a registered StringSchema. Otherwise, you should write an adapter for it like String2ObjectMapSchema.
  • Constructor Details

  • Method Details

    • findKeySchema

      protected StringSchema<K> findKeySchema(SchemaHolder holder, Class<K> type)
    • serialize

      public <To> void serialize(JsonAdapter<Object,To> adapter, JsonSerializationContext.Obj ctx, Map<K,V> map)
      Specified by:
      serialize in interface ObjectSchema<K>
      Type Parameters:
      To - the type the adapter serializes to.
      Parameters:
      adapter - the adapter used to serialize this object.
      ctx - the serialization context. Used to provide the key-value pairs.
      map - the object you're serializing.
    • instantiate

      public Map<K,V> instantiate()
      Specified by:
      instantiate in interface ObjectSchema<K>
      Returns:
      A new instance of the object this schema serializes.
    • deserialize

      public <To> void deserialize(JsonAdapter<Object,To> adapter, JsonDeserializationContext ctx, Map<K,V> map, String key)
      Specified by:
      deserialize in interface ObjectSchema<K>
      Type Parameters:
      To - the type the adapter serializes to.
      Parameters:
      adapter - the adapter used to deserialize this object.
      ctx - the deserialization context. Used to query the deserialization.
      map - the object you're deserializing the data into.
      key - the name of the field you're deserializing.
    • decodeKey

      protected <To> K decodeKey(JsonAdapter<Object,To> adapter, String key)
    • encodeKey

      protected <To> String encodeKey(JsonAdapter<Object,To> adapter, K key)