/** * fromMap converts a map into a Java object. * This version will see if there is a class parameter in the map, and dies if there is not. * @param map map to create the object from. * @return new object */ @Override public Object fromMap(Map<String, Object> map) { String clazz = (String) map.get( "class" ); Class cls = Reflection.loadClass( clazz ); return fromMap(map, cls); }
/** * fromMap converts a map into a Java object. * This version will see if there is a class parameter in the map, and dies if there is not. * @param map map to create the object from. * @return new object */ @Override public Object fromMap(Map<String, Object> map) { String clazz = (String) map.get( "class" ); Class cls = Reflection.loadClass( clazz ); return fromMap(map, cls); }
/** * 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; }
/** * Processes an collection of maps. * @param newInstance new instance we are injecting field into * @param field field we are injecting a value into */ @SuppressWarnings("unchecked") private void handleCollectionOfMaps( Object newInstance, FieldAccess field, Collection<Map<String, Object>> collectionOfMaps ) { Collection<Object> newCollection = Conversions.createCollection( field.type(), collectionOfMaps.size() ); Class<?> componentClass = field.getComponentClass(); if ( componentClass != null ) { for ( Map<String, Object> mapComponent : collectionOfMaps ) { newCollection.add( fromMap( mapComponent, componentClass ) ); } field.setObject( newInstance, newCollection ); } }
/** * fromMap converts a map into a java object. * @param map map to create the object from. * @param clazz the new instance type * @param excludeProperties the properties to exclude * @param <T> generic type capture * @return the new object */ @SuppressWarnings( "unchecked" ) public static <T> T fromMap( Map<String, Object> map, Class<T> clazz, String... excludeProperties ) { Set<String> ignoreProps = excludeProperties.length > 0 ? Sets.set(excludeProperties) : null; return new MapperComplex(FieldAccessMode.FIELD_THEN_PROPERTY.create( false ), ignoreProps, null, true).fromMap(map, clazz); }
/** * fromMap converts a map into a java object. * @param map map to create the object from. * @param clazz the new instance type * @param excludeProperties the properties to exclude * @param <T> generic type capture * @return the new object */ @SuppressWarnings( "unchecked" ) public static <T> T fromMap( Map<String, Object> map, Class<T> clazz, String... excludeProperties ) { Set<String> ignoreProps = excludeProperties.length > 0 ? Sets.set(excludeProperties) : null; return new MapperComplex(FieldAccessMode.FIELD_THEN_PROPERTY.create( false ), ignoreProps, null, true).fromMap(map, clazz); }
/** * Processes an collection of maps. * @param newInstance new instance we are injecting field into * @param field field we are injecting a value into */ @SuppressWarnings("unchecked") private void handleCollectionOfMaps( Object newInstance, FieldAccess field, Collection<Map<String, Object>> collectionOfMaps ) { Collection<Object> newCollection = Conversions.createCollection( field.type(), collectionOfMaps.size() ); Class<?> componentClass = field.getComponentClass(); if ( componentClass != null ) { for ( Map<String, Object> mapComponent : collectionOfMaps ) { newCollection.add( fromMap( mapComponent, componentClass ) ); } field.setObject( newInstance, newCollection ); } }
value = fromMap((Map) value, valueType); key = fromMap((Map) key, keyType); item = fromMap( ( Map<String, Object> ) item, parameterClass ); convertedArgumentList.set( index, item ); return true; item = fromMap( (Map<String, Object>) item, Reflection.loadClass(className)); convertedArgumentList.set(index, item); return true; } else if (o instanceof Map) { Map fromMap = ( Map ) o; o = fromMap( fromMap, componentType ); newList.add( o ); case MAP: case VALUE_MAP: convertedArgumentList.set(index, fromMap( (Map<String, Object>) item, parameterClass)); return true;
value = fromMap((Map) value, valueType); key = fromMap((Map) key, keyType); item = fromMap( ( Map<String, Object> ) item, parameterClass ); convertedArgumentList.set( index, item ); return true; item = fromMap( (Map<String, Object>) item, Reflection.loadClass(className)); convertedArgumentList.set(index, item); return true; } else if (o instanceof Map) { Map fromMap = ( Map ) o; o = fromMap( fromMap, componentType ); newList.add( o ); case MAP: case VALUE_MAP: convertedArgumentList.set(index, fromMap( (Map<String, Object>) item, parameterClass)); return true;
o = fromMap((Map) o, componentClass); if (componentClass.isInstance( o )) { Array.set(array, index, o);
o = fromMap((Map) o, componentClass); if (componentClass.isInstance( o )) { Array.set(array, index, o);