JAXB, MOXy, JSR-303, JPA - disable JSR-303 checks after disassembly?

I am receiving an XML message via an external service that I can unmount in a POJO using MOXy as my JAXB provider. Currently I am able to persist an entity using JPA (Hibernate) to the database and JSR-303 validations work as expected when invalid data is encountered.

My problem is that, to be persistent, I would like to add two fields to the POJO - the user id of the submitter and the date the entry was received. Adding the attributes works great and everything persists as expected. However, as soon as I add @NotNull constraints to the two extra fields (to protect writing to the same table from other processes), the unmarshal fails with the following error:

Violations violated with unmarshaled bean:

Is there a way to disable JSR-303 validation after disassembly? I have a large number of these that I will need to create in the near future, and having 2 different objects for each incoming message that needs to be stored would be less optimal.

Also - there will be other non-audit information that needs to be entered later, so adding another audit solution will not help.

Thanks in advance for your help!

+3


source to share


1 answer


To disable BV in MOXy:

 Map<String, BeanValidationMode> props = new HashMap<>();
 props.put(JAXBContextProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE);
 Class[] classes = new Class[] { Customer.class };
 JAXBContext jaxbContext = JAXBContext.newInstance(classes, props);

      



https://wiki.eclipse.org/EclipseLink/Examples/MOXy/BVinJAXB/GettingStarted

+1


source







All Articles