BeanUtils { public static void copyProperties( Object object, Map<String, Object> properties ) { Set<Map.Entry<String, Object>> props = properties.entrySet(); for ( Map.Entry<String, Object> entry : props ) { setPropertyValue( object, entry.getValue(), entry.getKey() ); } }  static Object getPropByPath( Object item, String... path ); static FieldAccess getField( Class clazz, String name ); static FieldAccess getField( Object object, String name ); static Map<String, FieldAccess> getFieldsFromObject( Class<?> cls ); static Map<String, FieldAccess> getFieldsFromObject( Object object ); static void setPropertyValue( final Object root,
                                         final Object newValue,
                                         final String... properties ); static void setPropertyValue( final Class<?> root, final Object newValue, final String... properties ); static Object getPropertyValue( final Object root, final String... properties ); static Class<?> getPropertyType( final Object root, final String property ); @SuppressWarnings ( "unchecked" ) static T idxGeneric( Class<T> t, Object object, final String path ); static List<T> idxList( Class<T> cls, Object items, String path ); static List idxList( Object items, String path ); static List<T> idxRecurse( Class<T> cls, Object items, String path ); static List idxRecurse( Object items, String path ); static Object idx( Object object, String path ); static Object indexOf(Object object, String path); static Object atIndex(Object object, String path); static Object findProperty(Object context, String propertyPath); static void injectIntoProperty( Object object, String path, Object value ); static void idx( Object object, String path, Object value ); static void idx( Class<?> cls, String path, Object value ); static Object getProp( Object object, final String property ); static int getPropertyInt( final Object root, final String... properties ); static int idxInt( Object object, String path ); static String idxStr( Object object, String path ); static byte getPropertyByte( final Object root, final String... properties ); static byte idxByte( Object object, String path ); static float getPropertyFloat( final Object root, final String... properties ); static float idxFloat( Object object, String path ); static short getPropertyShort( final Object root,
                                          final String... properties ); static Class<?> getPropertyPathType( final Object root,
                                          final String... properties ); static FieldAccess getPropertyPathField( final Object root,
                                                final String... properties ); static FieldAccess getPropertyPathField( final Class root,
                                                    final String... properties ); static short idxShort( Object object, String path ); static Class idxType( Object object, String path ); static FieldAccess idxField( Object object, String path ); static FieldAccess idxField( Class<?> cls, String path ); static char getPropertyChar( final Object root,
                                        final String... properties ); static char idxChar( Object object, String path ); static double getPropertyDouble( final Object root,
                                            final String... properties ); static double idxDouble( Object object, String path ); static long getPropertyLong( final Object root,
                                        final String... properties ); static long idxLong( Object object, String path ); static boolean getPropertyBoolean( final Object root,
                                              final String... properties ); static boolean idxBoolean( Object object, String path ); static Map<String, V> collectionToMap( String propertyKey, Collection<V> values ); static void copyPropertiesFromMap( final Object dest, final Map<String, Object> src ); static void copyProperties( Object object, Map<String, Object> properties ); @SuppressWarnings("all") static T copy( T item ); static T fieldByFieldCopy( T item ); static void copyProperties( Object src, Object dest ); static T createFromSrc( Object src, Class<T> dest ); static void copyProperties( Object src, Object dest, String... ignore); static void copyProperties( Object src, Object dest, Set<String> ignore); static Object idx( Object object, int index ); static void idx( Object object, int index, Object value ); static T idx( Class<T> type, Object object, String property ); static T atIndex( Class<T> type, Object object, String property ); static boolean isPropPath(String prop); static void setCollectionProperty(Collection<?> list, String propertyName, Object value); static void setIterableProperty(Iterable<?> list, String propertyName, Object value); static String asPrettyJsonString(Object bean); static String asPrettyJsonString(Mapper mapper, Object bean);  }
@Test public void test() { TestClass tc = new TestClass (); tc.init (); TestPrime prime = new TestPrime (); BeanUtils.copyProperties ( tc, prime ); boolean ok = prime.id.equals ( "foo" ) || die(); ok = prime.child.id.equals ( "child" ) || die(); ok &= Lists.list("1", "2").equals ( prime.players ) || die("" + prime.players); }
@Test public void test2() { TestClass tc = new TestClass (); tc.init(); TestPrime prime = new TestPrime (); BeanUtils.copyProperties ( tc, prime, "id" ); boolean ok = prime.id.equals ( "bar" ) || die(prime.id); ok = prime.child.id.equals ( "bar" ) || die(prime.child.id); ok = prime.child.time == 1L || die(); ok &= Lists.list("1", "2").equals ( prime.players ) || die("" + prime.players); }