/** * This converts a list of maps to objects. * I always forget that this exists. I need to remember. * * @param list the input list * @param <T> generics * @return a new list */ @Override public <T> List<T> convertListOfMapsToObjects(List<Map> list, Class<T> componentType) { List<Object> newList = new ArrayList<>( list.size() ); for ( Object obj : list ) { if ( obj instanceof Value ) { obj = ( ( Value ) obj ).toValue(); } if ( obj instanceof Map ) { Map map = ( Map ) obj; if ( map instanceof ValueMapImpl) { newList.add( fromValueMap( ( Map<String, Value> ) map, componentType ) ); } else { newList.add( fromMap( map, componentType ) ); } } else { newList.add( Conversions.coerce( componentType, obj ) ); } } return ( List<T> ) newList; }
/** * This converts a list of maps to objects. * I always forget that this exists. I need to remember. * * @param list the input list * @param <T> generics * @return a new list */ @Override public <T> List<T> convertListOfMapsToObjects(List<Map> list, Class<T> componentType) { List<Object> newList = new ArrayList<>( list.size() ); for ( Object obj : list ) { if ( obj instanceof Value ) { obj = ( ( Value ) obj ).toValue(); } if ( obj instanceof Map ) { Map map = ( Map ) obj; if ( map instanceof ValueMapImpl) { newList.add( fromValueMap( ( Map<String, Value> ) map, componentType ) ); } else { newList.add( fromMap( map, componentType ) ); } } else { newList.add( Conversions.coerce( componentType, obj ) ); } } return ( List<T> ) newList; }
/** * Creates an object from a value map. * * This does some special handling to take advantage of us using the value map so it avoids creating * a bunch of array objects and collections. Things you have to worry about when writing a * high-speed JSON serializer. * @return new object from value map */ @Override @SuppressWarnings("unchecked") public Object fromValueMap(final Map<String, Value> valueMap ) { try { String className = valueMap.get( "class" ).toString(); Class<?> cls = Reflection.loadClass( className ); return fromValueMap( valueMap, cls ); } catch ( Exception ex ) { return handle(Object.class, Str.sputs("fromValueMap", "map", valueMap, "fieldAccessor", fieldsAccessor), ex); } }
/** * Creates an object from a value map. * * This does some special handling to take advantage of us using the value map so it avoids creating * a bunch of array objects and collections. Things you have to worry about when writing a * high-speed JSON serializer. * @return new object from value map */ @Override @SuppressWarnings("unchecked") public Object fromValueMap(final Map<String, Value> valueMap ) { try { String className = valueMap.get( "class" ).toString(); Class<?> cls = Reflection.loadClass( className ); return fromValueMap( valueMap, cls ); } catch ( Exception ex ) { return handle(Object.class, Str.sputs("fromValueMap", "map", valueMap, "fieldAccessor", fieldsAccessor), ex); } }
Class<?> clazz = field.type(); if ( !clazz.isInterface() && !Typ.isAbstract( clazz ) ) { objectValue = fromValueMap( ( Map<String, Value> ) objectValue, field.type() ); } else { String className = (( Map<String, Value> ) objectValue) Class<?> cls = Reflection.loadClass( className ); objectValue = fromValueMap( ( Map<String, Value> ) objectValue, cls );
Class<?> clazz = field.type(); if ( !clazz.isInterface() && !Typ.isAbstract( clazz ) ) { objectValue = fromValueMap( ( Map<String, Value> ) objectValue, field.type() ); } else { String className = (( Map<String, Value> ) objectValue) Class<?> cls = Reflection.loadClass( className ); objectValue = fromValueMap( ( Map<String, Value> ) objectValue, cls );
switch (value.type()) { case MAP: objValue = fromValueMap( ( Map<String, Value> ) objValue, clazz ); break; case LIST:
switch (value.type()) { case MAP: objValue = fromValueMap( ( Map<String, Value> ) objValue, clazz ); break; case LIST:
Object oValue = value.toValue(); if ( oValue instanceof Map ) { newCollection.add( fromValueMap( ( Map ) oValue, componentClass ) );
Object oValue = value.toValue(); if ( oValue instanceof Map ) { newCollection.add( fromValueMap( ( Map ) oValue, componentClass ) );