0

How would you "clone" a Java Object and only cloning non-null fields?

Consider this code:

MyObject original = getObject(); 
MyObject copyOfNonNullFields = copy(original, MyObject.lass); 

As such it would work in any arbitrary Java object. I've checked Dozer http://dozer.sourceforge.net/ but it needs custom XML mapping for each object class to copy.

Fireburn
  • 981
  • 6
  • 20
  • How about https://github.com/EsotericSoftware/kryo – quarks Mar 26 '21 at 21:12
  • 1
    The only way I see to do this in a generic way would be through reflection. The real question is: why do you need this capability? Sounds like an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Turing85 Mar 26 '21 at 21:15

0 Answers0