Class KsonTypeMapper

java.lang.Object
org.nustaq.kson.KsonTypeMapper

public class KsonTypeMapper extends Object
simple implementation of type mapper. * Maps Classes to short string names and vice versa. * allows to add user-defined type conversions (e.g. Date, Collections) This default implementation supports Date<=>String and Collections<=>Array coercion.
  • Field Details

    • NULL_LITERAL

      public static final Object NULL_LITERAL
    • useSimplClzName

      protected boolean useSimplClzName
    • typeMap

      protected HashMap<String,Class> typeMap
    • reverseTypeMap

      protected HashMap<Class,String> reverseTypeMap
    • dateTimeInstance

      protected DateFormat dateTimeInstance
  • Constructor Details

    • KsonTypeMapper

      public KsonTypeMapper()
  • Method Details

    • getType

      public Class getType(String type)
    • map

      public KsonTypeMapper map(String name, Class c)
    • map

      public KsonTypeMapper map(Object... stringAndClasses)
    • map

      public KsonTypeMapper map(Class... c)
    • isUseSimplClzName

      public boolean isUseSimplClzName()
    • setUseSimplClzName

      public void setUseSimplClzName(boolean useSimplClzName)
    • coerceReading

      public Object coerceReading(Class type, Object readObject)
      map given Object to a target type. (needs support in coerceWriting also) Note one could add a pluggable Serializer/Coercer pattern here if required. Skipped for now for simplicity.
      Parameters:
      type - - of target field
      readObject - - object read from string
      Returns:
    • getDateTimeInstance

      public DateFormat getDateTimeInstance()
    • setDateTimeInstance

      public void setDateTimeInstance(DateFormat dateTimeInstance)
    • mapLiteral

      public Object mapLiteral(String type)
    • getStringForType

      public String getStringForType(Class<? extends Object> aClass)