I have a sample input XML with below structure:
<students>
<student>
<name>Peter</name>
<intern>
<internLocation>Ohio</internLocation>
</intern>
</student>
<student>
<name>John</name>
</student>
</students>
And beanio config:
<beanio xmlns="http://www.beanio.org/2012/03">
<stream name="students" format="xml" strict="true">
<record name="student" class="com.testapp.model.Student">
<field name="studentName" xmlName="name" maxLength="20" />
<segment name="intern" minOccurs="0">
<field name="internLocation" maxLength="50" minOccurs="0" default="" />
</segment>
</record>
</stream>
</beanio>
And Model class:
public class Student {
private String studentName;
private String internLocation;
(...)
}
As you can see <intern>
segment is optional. How can I default internLocation
field of Student
class to some value in case the segment is not present?
I've tried annotating the field like below but still null value is coming:
@Field(defaultValue = "")
private String internLocation;