/** * * @param componentType The component type of the created list * @param list the input list * @param <T> T * @return T */ public static <T> List<T> convertListOfMapsToObjects(Class<T> componentType, List<Map> list) { return mapper.convertListOfMapsToObjects(list, componentType); }
/** Convert an item from a list into a class using the classes constructor. * * REFACTOR: Can't this just be from collection? * REFACTOR * * @param argList list if arguments * @param clazz the type of the object we are creating * @param <T> generics * @return the new object that we just created. */ public static <T> T fromList( List<?> argList, Class<T> clazz ) { return mapper.fromList(argList, clazz); }
protected final <T> T convert( Class<T> clz, Object object ) { if (object == null ) { return null; } TypeType coerceTo = TypeType.getType(clz); switch ( coerceTo ) { case MAP: case LIST: case OBJECT: return (T)object; } TypeType coerceFrom = TypeType.getType(object.getClass()); switch ( coerceFrom ) { case VALUE_MAP: return mapper.fromValueMap( ( Map<String, Value> ) object, clz ); case MAP: return mapper.fromMap ( ( Map<String, Object> ) object, clz ); case VALUE: return (T)( (Value) object).toValue (); case LIST: return (T) mapper.convertListOfMapsToObjects( (List<Map>)object, clz); default: if ( Typ.isBasicTypeOrCollection(clz) ) { return Conversions.coerce(coerceTo, clz, object); } else { return (T)object; } } }
/** * 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. * @param respectIgnore honor @JsonIgnore, transients, etc. of the field * @param view the view of the object which can ignore certain fields given certain views * @param fieldsAccessor how we are going to access the fields (by field, by property, combination) * @param cls the new type * @param ignoreSet a set of properties to ignore * @param valueMap value map * @param <T> type * @return new object from value map */ @SuppressWarnings("unchecked") public static <T> T fromValueMap( boolean respectIgnore, String view, final FieldsAccessor fieldsAccessor, final Map<String, Value> valueMap, final Class<T> cls, Set<String> ignoreSet ) { Mapper mapper = new MapperComplex(fieldsAccessor, ignoreSet, view, respectIgnore); return mapper.fromValueMap(valueMap, cls); }
/** * This could be refactored to use core.TypeType class and it would run faster. * * Converts an object into a map * @param object the object that we want to convert * @return map map representation of the object */ public static Map<String, Object> toMap( final Object object ) { return mapper.toMap(object); }
/** Convert an object to a list. * * @param object the object we want to convert to a list * @return new list from an object */ public static List<?> toList( Object object) { return mapper.toList(object); }
/** * Creates a list of maps from a list of class instances. * @param collection the collection we are coercing into a field value * @return the return value. */ public static List<Map<String, Object>> toListOfMaps( Collection<?> collection ) { return mapper.toListOfMaps(collection); }
protected final <T> T convert( Class<T> clz, Object object ) { if (object == null ) { return null; } TypeType coerceTo = TypeType.getType(clz); switch ( coerceTo ) { case MAP: case LIST: case OBJECT: return (T)object; } TypeType coerceFrom = TypeType.getType(object.getClass()); switch ( coerceFrom ) { case VALUE_MAP: return mapper.fromValueMap( ( Map<String, Value> ) object, clz ); case MAP: return mapper.fromMap ( ( Map<String, Object> ) object, clz ); case VALUE: return (T)( (Value) object).toValue (); case LIST: return (T) mapper.convertListOfMapsToObjects( (List<Map>)object, clz); default: if ( Typ.isBasicTypeOrCollection(clz) ) { return Conversions.coerce(coerceTo, clz, object); } else { return (T)object; } } }
/** * 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. * @param respectIgnore honor @JsonIgnore, transients, etc. of the field * @param view the view of the object which can ignore certain fields given certain views * @param fieldsAccessor how we are going to access the fields (by field, by property, combination) * @param cls the new type * @param ignoreSet a set of properties to ignore * @param valueMap value map * @param <T> type * @return new object from value map */ @SuppressWarnings("unchecked") public static <T> T fromValueMap( boolean respectIgnore, String view, final FieldsAccessor fieldsAccessor, final Map<String, Value> valueMap, final Class<T> cls, Set<String> ignoreSet ) { Mapper mapper = new MapperComplex(fieldsAccessor, ignoreSet, view, respectIgnore); return mapper.fromValueMap(valueMap, cls); }
/** * This could be refactored to use core.TypeType class and it would run faster. * * Converts an object into a map * @param object the object that we want to convert * @return map map representation of the object */ public static Map<String, Object> toMapWithType( final Object object ) { return mapperWithType.toMap(object); }
/** Convert an object to a list. * * @param object the object we want to convert to a list * @return new list from an object */ public static List<?> toList( Object object) { return mapper.toList(object); }
/** * Creates a list of maps from a list of class instances. * @param collection the collection we are coercing into a field value * @return the return value. */ public static List<Map<String, Object>> toListOfMaps( Collection<?> collection ) { return mapper.toListOfMaps(collection); }
protected final <T> T convert( Class<T> clz, Object object ) { if (object == null ) { return null; } TypeType coerceTo = TypeType.getType(clz); switch ( coerceTo ) { case MAP: case LIST: case OBJECT: return (T)object; } TypeType coerceFrom = TypeType.getType(object.getClass()); switch ( coerceFrom ) { case VALUE_MAP: return mapper.fromValueMap( ( Map<String, Value> ) object, clz ); case MAP: return mapper.fromMap ( ( Map<String, Object> ) object, clz ); case VALUE: return (T)( (Value) object).toValue (); case LIST: return (T) mapper.convertListOfMapsToObjects( (List<Map>)object, clz); default: if ( Typ.isBasicTypeOrCollection(clz) ) { return Conversions.coerce(coerceTo, clz, object); } else { return (T)object; } } }
/** * From map. * @param map map to create the object from. * @param clazz the new instance type * @param <T> generic type capture * @return new object */ @SuppressWarnings( "unchecked" ) public static <T> T fromMap( Map<String, Object> map, Class<T> clazz ) { return mapper.fromMap(map, clazz); }
private <T> T finalExtract( Class<T> type, Object object ) { if (object instanceof Map ) { Map<String, Value> objectMap = ( Map<String, Value> ) object; return mapper.fromValueMap( objectMap, type ); } if (object instanceof ValueContainer) { object = ((ValueContainer) object).toValue(); } if (object instanceof List ) { List<Object> list = ( List<Object> ) object; return MapObjectConversion.fromList ( list, type ); } else { return (T)object; } }
/** * * @param componentType The component type of the created list * @param list the input list * @param <T> T * @return T */ public static <T> List<T> convertListOfMapsToObjects(Class<T> componentType, List<Map> list) { return mapper.convertListOfMapsToObjects(list, componentType); }
/** * This could be refactored to use core.TypeType class and it would run faster. * * Converts an object into a map * @param object the object that we want to convert * @return map map representation of the object */ public static Map<String, Object> toMapWithType( final Object object ) { return mapperWithType.toMap(object); }
/** Convert an item from a list into a class using the classes constructor. * * REFACTOR: Can't this just be from collection? * REFACTOR * * @param argList list if arguments * @param clazz the type of the object we are creating * @param <T> generics * @return the new object that we just created. */ public static <T> T fromList( List<?> argList, Class<T> clazz ) { return mapper.fromList(argList, clazz); }
/** * 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 */ public static Object fromMap( Map<String, Object> map ) { return mapper.fromMap(map); }