public static void main(String[] args) { // init mapper MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); mapperFactory.classMap(Source.class, Destination.class). field("message", "text").register(); MapperFacade mapper = mapperFactory.getMapperFacade(); // convert Source source = new Source("Hello World!"); Destination destObject = mapper.map(source, Destination.class); destObject.print(); // print Hello World! } }
public boolean apply(FieldMap fieldMap) { return (fieldMap.getSource().isListElement() || fieldMap.getSource().isArrayElement()) && (fieldMap.getDestination().getType().isImmutable() || (!fieldMap.getDestination().isCollection() && !fieldMap.getDestination().isArray() && !fieldMap.getDestination().isMap() && !fieldMap.getDestination() .isEnum())); } };
public boolean apply(FieldMap fieldMap) { return fieldMap.getSource().isMapKey() && (fieldMap.getDestination().getType().isImmutable() || (!fieldMap.getDestination().isCollection() && !fieldMap.getDestination().isArray() && !fieldMap.getDestination().isMap() && !fieldMap.getDestination() .isEnum())); } };
public static FieldMap mapValues(Type<?> aType, Type<?> bType) { Property aProperty = new Property.Builder().name("value").getter("getValue()").setter("setValue(%s)").type(aType).build(null); Property bProperty = aProperty.copy(bType); return new FieldMap(aProperty, bProperty, null, null, MappingDirection.A_TO_B, false, null, false, null, null); } }
private FieldMap mapConstructorArgument(FieldMap existing, Type<?> argumentType, boolean byDefault) { final Property destProp = new Property.Builder() .name(existing.getDestination().getName()) .getter(existing.getDestination().getName()) .type(argumentType) .build(); return new FieldMap(existing.getSource(), destProp, null, null, MappingDirection.A_TO_B, false, existing.getConverterId(), byDefault, null, null); } }
public boolean appliesTo(FieldMap fieldMap) { return (fieldMap.getSource().getType().isPrimitive() && !TypeFactory.TYPE_OF_OBJECT.equals(fieldMap.getDestination().getType())) || fieldMap.getDestination().getType().isPrimitive(); }
/** * Map a field in one direction only (from fieldNameA to fieldNameB) * * @param fieldNameA * the (source) fieldName from type A * @param fieldNameB * the (destination) fieldName from type B * @return */ public ClassMapBuilder<A, B> fieldAToB(String fieldNameA, String fieldNameB) { return fieldMap(fieldNameA, fieldNameB).aToB().add(); }
public boolean apply(FieldMap fieldMap) { return fieldMap.getSource().getType().isImmutable() && fieldMap.getDestination().isAssignableFrom(fieldMap.getSource()); } };
/** * Begin a new mapping for the specified class and type. * * @param aType * @param bType * @return a new ClassMapBuilder instance for the specified types */ public <A, B> ClassMapBuilder<A, B> map(Class<A> aType, Type<B> bType) { return getNewClassMapBuilder(TypeFactory.<A> valueOf(aType), bType); }
/** * * * @param fieldNameA * @param fieldB * @param byDefault * @return */ public FieldMapBuilder<A, B> fieldMap(String fieldNameA, Property.Builder fieldB, boolean byDefault) { return new FieldMapBuilder<A, B>(this, resolvePropertyForA(fieldNameA), fieldB.build((PropertyResolver) propertyResolver), byDefault, sourcesMappedOnNull, destinationsMappedOnNull); }
/** * * * @param fieldA * @param fieldNameB * @param byDefault * @return */ public FieldMapBuilder<A, B> fieldMap(Property.Builder fieldA, String fieldNameB, boolean byDefault) { return new FieldMapBuilder<A, B>(this, fieldA.build((PropertyResolver) propertyResolver), resolvePropertyForB(fieldNameB), byDefault, sourcesMappedOnNull, destinationsMappedOnNull); }
/** * Adds the FieldMap configured by this builder to it's containing * ClassMapBuilder; use this method to complete specifications on a given * field mapping and return to the containing builder. * * @return the containing ClassMapBuilder instance */ public ClassMapBuilder<A, B> add() { classMapBuilder.addFieldMap(toFieldMap()); return classMapBuilder; }
/** * * * @param fieldA * @param fieldB * @param byDefault * @return */ public FieldMapBuilder<A, B> fieldMap(Property.Builder fieldA, Property.Builder fieldB, boolean byDefault) { return new FieldMapBuilder<A, B>(this, fieldA.build((PropertyResolver) propertyResolver), fieldB.build((PropertyResolver) propertyResolver), byDefault, sourcesMappedOnNull, destinationsMappedOnNull); }
/** * Creates a FieldMap for the Map keys from A to B * * @param aType * @param bType * @return a reference to this FieldMapBuilder */ public static FieldMap mapKeys(final Type<?> aType, final Type<?> bType) { Property aProperty = new Property.Builder().name("key").getter("getKey()").setter("setKey(%s)").type(aType).build(null); Property bProperty = aProperty.copy(bType); return new FieldMap(aProperty, bProperty, null, null, MappingDirection.A_TO_B, false, null, false, null, null); }
public boolean apply(FieldMap fieldMap) { return (fieldMap.getDestination().isListElement() || fieldMap.getDestination().isArrayElement()) && (fieldMap.getSource().getType().isImmutable() || (!fieldMap.getSource().isCollection() && !fieldMap.getSource().isArray() && !fieldMap.getSource().isMap() && !fieldMap.getSource().isEnum())); } };
public boolean apply(FieldMap fieldMap) { return fieldMap.getDestination().isMapKey() && (fieldMap.getSource().getType().isImmutable() || (!fieldMap.getSource().isCollection() && !fieldMap.getSource().isArray() && !fieldMap.getSource().isMap() && !fieldMap.getSource().isEnum())); } };
public boolean apply(FieldMap fieldMap) { return fieldMap.getSource().getType().isPrimitive() || fieldMap.getDestination().getType().isPrimitive(); } };
/** * * * @param fieldA * @param fieldB * @param byDefault * @return */ public FieldMapBuilder<A,B> fieldMap(String fieldNameA, Property.Builder fieldB, boolean byDefault) { return new FieldMapBuilder<A,B>(this, resolvePropertyForA(fieldNameA), fieldB.build((PropertyResolver)propertyResolver), byDefault, sourcesMappedOnNull, destinationsMappedOnNull); }
public static FieldMap mapKeys(Type<?> aType, Type<?> bType) { Property aProperty = new Property.Builder().name("key").getter("getKey()").setter("setKey(%s)").type(aType).build(null); Property bProperty = aProperty.copy(bType); return new FieldMap(aProperty, bProperty, null, null, MappingDirection.A_TO_B, false, null, false, null, null); }