1

I have two objects with name Site and AppSite, both has same fields like below. Is there any util class to copy all the fields from AppSite to Site, like BeanUtils.copyProperties.

public class AmsSite implements Serializable{
    private long siteId;
    private String name;
    private String routingId;
    private String siteType;

    private List<AmsPlatform> platforms;
    private List<AmsProvider> providers;

public class Site implements Serializable{
    private long siteId;
    private String name;
    private String routingId;
    private String siteType;

    private List<Platform> platforms;
    private List<Provider> providers;

If you see in above two pojo, i have two list of object fields. Both that object also same like Site and AmsSite object only. Has same field name but different class name.

BeanUtils.copyProperties is copying all the literal field values from AppSite to Site properly, but not the inner object. (I mean deep copy is not happening). I saw Serialization.clone in apache common lang works for deep copy, but that works only if we have same class name. My case is bit different same field name but different class name.

Mohan
  • 699
  • 1
  • 11
  • 27

1 Answers1

0

You could try an object mapper like Orika but I'm not sure if it will work with inner classes.

If you have a lot of these type of objects you might want to consider restructuring your objects to fit an easier pattern.

Lee
  • 738
  • 3
  • 13