Let's say I have a 10 unique POJOs each with 10 uniquely named fields.
This POJO is a deserialized SOAP response. I want to "copy" the fields from the SOAP POJOs over to a POJO that represents a JSON object, and then serialize that POJO.
Let's name our SOAP objects o0 ... o9
Let's name our SOAP fields f0 ... f9
Let's name our JSON object jo
Let's name our JSON fields f0 ... f99
Finally, all fields are containers for values, so each field has a .getValue() method.
Assuming all our fields have getters and setters, the only way to do this, from my understanding, is hardcoding the following:
jo.setF0(o0.getF0().getValue());
jo.setF1(o0.getF1().getValue());
...
jo.setF49(o4.getF9().getValue());
...
jo.setF99(o9.getF9().getValue());
Now, the problem is that any of the fields belonging to o0 ... o9 MAY be null, which will cause a NullPointerException.
Is there any way to get around this without writing 100 try/catch blocks?