Unmarshalling empty tag into new instances



I am trying to unmarshall something like below into their JAXB equivalents, and the fields are as expected being populated with nulls


XML



<University>
<StudentFirstNames/>
</University>


JAXB Pojo



public class University {
List<StudentFirstNames> studentFirstNames = null;

public void getStudentFirstNames() {
return studentFirstNames
}

public void setStudentFirstNames() {
this.studentFirsNames = studentFirstNames;
}
}


After unmarshalling I am returned back null when I lookup the member in the JAXB object



university.getStudentFirstNames() --> null


In this specific situation I am trying to resolve, I need to replace empty tags with new instance of that particular type. For example in the above, I am expecting back a new ArrayList () instead of null. I know this sounds counter intuitive but that is what I have to do for satisying code downstream.


Is there a global fix to resolve such instances. Thanks in advance.


No comments:

Post a Comment