TuplePojo implements InvocationHandler { public static <T> T wrapping(Tuple tuple, Class<? extends T> pojoClass) { return pojoClass.cast(Proxy.newProxyInstance(pojoClass.getClassLoader(), new Class<?>[] { pojoClass }, new TuplePojo(tuple, getTupleMap(pojoClass, tuple.getSchema())))); } TuplePojo(Tuple tuple, Map<Method, TupleKey> keyMap); static T wrapping(Tuple tuple, Class<? extends T> pojoClass); @Override Object invoke(Object proxy, Method method, Object[] args); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void mapsTuple() { Tuple tuple = schema.makeWith("Arthur Putey", 41, ImmutableMap.of("home", "07773 456789")); Person person = TuplePojo.wrapping(tuple, Person.class); assertThat(person.getName(), equalTo("Arthur Putey")); assertThat(person.getAge(), equalTo(41)); assertThat(person.getTelephoneNumbers().get("home"), equalTo("07773 456789")); }
@Test public void equality() { Tuple tuple1 = schema.makeWith("Arthur Putey", 41, ImmutableMap.of("home", "07773 456789")); Tuple tuple2 = schema.makeWith("Arthur Putey", 41, ImmutableMap.of("home", "07773 456789")); Person person1 = TuplePojo.wrapping(tuple1, Person.class); Person person2 = TuplePojo.wrapping(tuple2, Person.class); assertThat(person1, equalTo(person2)); }