I'm trying to setup a simple Jersey JAX-RS application using MOXy for JAXB JSON support and I wanted to customise the unmarshaller. I did the following:
@Provider
public class CustomProvider extends ConfigurableMoxyJsonProvider{
@Override
protected void preReadFrom(..., Unmarshaller unmarshaller) throws JAXBException{
super.preReadFrom(...);
System.out.println("preReadFrom entered");
unmarshaller.setEventHandler(new ValidationEventHandler(){
@Override
public boolean handleEvent(ValidationEvent event){
System.out.println("Entered handleEvent");
return false;
}
});
}
}
I wrote an override for preReadFrom and set an event handler on the unmarshaller. When I pass an invalid JSON body, print statement in preReadFrom executes but not the one in event handler. So the provider is registered properly but the event handler is not being called.
What might cause this issue?
What I want to achieve is when a user passes extraneous attributes in the JSON body, I want to throw an error (By default, these attributes are ignored). Searching on various websites, adding an event handler is the only way to do that. It would be great if I can achieve this in a different way too.