I have 3 big domain classes like below, and I need their values as a string array like in the example.
It is very time consuming and error prone to write all fields one by one like this, is there a quick way to this? It will iterate over all fields and get their string values?
Maybe with guava or reflection?
Class Cart1{
//Domain class with 100s of Items with getters and setters
//..
public String[] toStringArray() {
return new String[]{
nullToEmpty(String.valueOf(getSomeItem1())),
nullToEmpty(String.valueOf(getOtherItem2())),
.
.
nullToEmpty(String.valueOf(getSomeFreakItem100())),
}
}
Edit : I need this for opencvs, it expects for a String[] as in this example: