Reputation: 1
Say I'm trying to unmarshal an XML file with an integer field (xs:integer): 13131546456131653154156415616
This value is > Java Long's max value.
I was hoping to get and catch an exception when Jaxb tried to unmarshal it.
Instead, there is no exception, and my pojo's object.Value is set to null.
Is there a way to detect when this happens and log it?
I've tried using vec, but it caught nothing (empty list):
ValidationEventCollector vec = new ValidationEventCollector();
JAXBContext jaxbContext = JAXBContext.newInstance(MyPojo.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.setEventHandler(vec);
System.out.println(vec.getEvents().length);
MyPojo model = (MyPojo) jaxbUnmarshaller.unmarshal(new FileInputStream(file));
Upvotes: 0
Views: 279
Reputation: 159096
xs:integer
is not limited, it can be values of any length.
The comparable Java type is BigInteger
.
xs:int
is however constrained to:
maxInclusive = 2147483647 minInclusive = -2147483648
And xs:long
is constrained to:
maxInclusive = 9223372036854775807 minInclusive = -9223372036854775808
So if you want the XML Schema Validator to check the value ranges, use the appropriate type.
Upvotes: 2