Normalize java bean property names
•
Java
I have a bunch of third-party Java classes that use different attribute names to implement the same attributes:
public class Foo {
public String getReferenceID();
public void setReferenceID(String id);
public String getFilename();
public void setFilename(String fileName);
}
public class Bar {
public String getRefID();
public void setRefID(String id);
public String getFileName();
public void setFileName(String fileName);
}
I hope to solve these problems in a standardized form so that I can handle them polymorphically, so that I can use Apache BeanUtils to do these things, such as:
PropertyUtils.copyProperties(object1,object2);
Obviously, writing an adapter for each class would be trivial
public class CanonicalizedBar implements CanonicalizedBazBean {
public String getReferenceID() {
return this.delegate.getRefID();
}
// etc.
}
But I wonder if there is anything broader and more dynamic? Something will need a one to many attribute name equivalent map, as well as a proxy class, and generate an adapter?
Solution
I've never used it, but I think you're looking for dozer:
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
