I want to reflect from class A to class B, but they two have difference filedNames, how to make it fast to set A's field to B's field.
@Data // lombok
class A {
private Long id;
private String name;
}
@Data
class B {
private Long userId;
private String userName;
}
class MainClass {
@Test
public void testReflect() {
A a = new A();
a.setId(1L);
a.setName("testName");
B b = new B();
// how to reflect a.id to b.userId and a.name to b.userName
}
}
just see the MainClass and how to reflect a.id to b.userId and a.name to b.userName? I've tried add annotation @JsonProperty("name")
on class B, and use DozerBeanMapper
, but it failed to resolve my problem;
Aucun commentaire:
Enregistrer un commentaire