i have a XML Jaxb class to set with XMLGregorianCalendar type. But we are supposed to set only year in this attribute.
XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(new
GregorianCalendar());
xmlCal.setYear(2021);
xmlObject.setBuiltYear(xmlCal);
// xmlCal.getYear() will give me year but its type int , so setter method not accepting it. If
has to be of type XMLGregorianCalendar only with year.
If i set it like above its giving 2021-09-23T10:19:38.346-04:00 but i need only year with type XMLGregorianCalendar . how we can do that ?
Use
XMLGregorianCalendar#clearbefore setting the year.Demo:
Output:
ONLINE DEMO