src/main/java/org/nustaq/kson/KsonTypeMapper.java
public Object coerceReading(Class type, Object readObject) {
        if (type==null)
            return readObject;
        // make hashmaps from arrays. warning: for optimal performance, use direct arrays[] only in your serialized classes
        if ( Map.class.isAssignableFrom(type) && readObject.getClass().isArray() ) {
            try {
                Map c = (Map) type.newInstance();
                int len = Array.getLength(readObject);
                for ( int i = 0; i < len; i+=2 ) {
                    c.put(Array.get(readObject, i), Array.get(readObject, i + 1));
                }
                return c;
            } catch (Exception e) {
                logger.log(FSTLogger.Level.INFO, "Exception thrown by newInstance", e);
            }
        } else // make collections from arrays. warning: for optimal performance, use direct arrays[] only in your serialized classes
            if ( Collection.class.isAssignableFrom(type) && readObject.getClass().isArray() ) {
            try {
                if ( type.isInterface() ) {
                    if ( List.class.isAssignableFrom(type) ) {
                        type = ArrayList.class;
                    } else if (Map.class.isAssignableFrom(type) ) {
                        type = HashMap.class;
                    }
                }
                Collection c = (Collection) type.newInstance();
                int len = Array.getLength(readObject);
                for ( int i = 0; i < len; i++ ) {
                    c.add(Array.get(readObject,i));
                }
                return c;
            } catch (Exception e) {
                logger.log(FSTLogger.Level.ERROR, "Exception thrown by newInstance", e);
            }
        } else if ( Date.class.isAssignableFrom(type) && readObject instanceof String) {
            try {
                return dateTimeInstance.parse((String) readObject);
            } catch (ParseException pe) {
                logger.log(FSTLogger.Level.ERROR, "Failed to parse date", pe);
            }
        } else if ( (type == char.class || Character.class.isAssignableFrom(type)) && readObject instanceof String ) {
            return ((String) readObject).charAt(0);
        }
        return readObject;
    }
public Object coerceReading(Class type, Object readObject) {
        if (type==null)
            return readObject;
        // make hashmaps from arrays. warning: for optimal performance, use direct arrays[] only in your serialized classes
        if ( Map.class.isAssignableFrom(type) && readObject.getClass().isArray() ) {
            try {
                Map c = (Map) type.newInstance();
                int len = Array.getLength(readObject);
                for ( int i = 0; i < len; i+=2 ) {
                    c.put(Array.get(readObject, i), Array.get(readObject, i + 1));
                }
                return c;
            } catch (Exception e) {
                logger.log(FSTLogger.Level.INFO, "Exception thrown by newInstance", e);
            }
        } else // make collections from arrays. warning: for optimal performance, use direct arrays[] only in your serialized classes
            if ( Collection.class.isAssignableFrom(type) && readObject.getClass().isArray() ) {
            try {
                if ( type.isInterface() ) {
                    if ( List.class.isAssignableFrom(type) ) {
                        type = ArrayList.class;
                    } else if (Map.class.isAssignableFrom(type) ) {
                        type = HashMap.class;
                    }
                }
                Collection c = (Collection) type.newInstance();
                int len = Array.getLength(readObject);
                for ( int i = 0; i < len; i++ ) {
                    c.add(Array.get(readObject,i));
                }
                return c;
            } catch (Exception e) {
                logger.log(FSTLogger.Level.ERROR, "Exception thrown by newInstance", e);
            }
        } else if ( Date.class.isAssignableFrom(type) && readObject instanceof String) {
            try {
                return dateTimeInstance.parse((String) readObject);
            } catch (ParseException pe) {
                logger.log(FSTLogger.Level.ERROR, "Failed to parse date", pe);
            }
        } else if ( (type == char.class || Character.class.isAssignableFrom(type)) && readObject instanceof String ) {
            return ((String) readObject).charAt(0);
        }
        return readObject;
    }
public Object coerceReading ( Class type , Object readObject ) { if ( type == null ) return readObject ; // make hashmaps from arrays. warning: for optimal performance, use direct arrays[] only in your serialized classes if ( Map . class . isAssignableFrom ( type ) && readObject . getClass ( ) . isArray ( ) ) { try { Map c = ( Map ) type . newInstance ( ) ; int len = Array . getLength ( readObject ) ; for ( int i = 0 ; i < len ; i += 2 ) { c . put ( Array . get ( readObject , i ) , Array . get ( readObject , i + 1 ) ) ; } return c ; } catch ( Exception e ) { logger . log ( FSTLogger . Level . INFO , "Exception thrown by newInstance" , e ) ; } } else // make collections from arrays. warning: for optimal performance, use direct arrays[] only in your serialized classes if ( Collection . class . isAssignableFrom ( type ) && readObject . getClass ( ) . isArray ( ) ) { try { if ( type . isInterface ( ) ) { if ( List . class . isAssignableFrom ( type ) ) { type = ArrayList . class ; } else if ( Map . class . isAssignableFrom ( type ) ) { type = HashMap . class ; } } Collection c = ( Collection ) type . newInstance ( ) ; int len = Array . getLength ( readObject ) ; for ( int i = 0 ; i < len ; i ++ ) { c . add ( Array . get ( readObject , i ) ) ; } return c ; } catch ( Exception e ) { logger . log ( FSTLogger . Level . ERROR , "Exception thrown by newInstance" , e ) ; } } else if ( Date . class . isAssignableFrom ( type ) && readObject instanceof String ) { try { return dateTimeInstance . parse ( ( String ) readObject ) ; } catch ( ParseException pe ) { logger . log ( FSTLogger . Level . ERROR , "Failed to parse date" , pe ) ; } } else if ( ( type == char . class || Character . class . isAssignableFrom ( type ) ) && readObject instanceof String ) { return ( ( String ) readObject ) . charAt ( 0 ) ; } return 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.

@param type - of target field
@param readObject - object read from string
@return
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 .