I have 3 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, maybe there is a quicker way? It will iterate over all fields and get their string values
Maybe with guava or reflection?
Class Cart1{
//Domain class with 100s of fields with getters & 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: