How to configure JAXB / Moxy to throw an error on potential lost data in XML

白昼怎懂夜的黑 提交于 2019-12-06 11:45:49
bdoughan

You can set an instance of ValidationEventHandler on the Unmarshaller to collect of fail on this type of issue.

public class DeserializationEventHandler implements ValidationEventHandler
{
private static final Logger LOG = LoggerFactory.getLogger(DeserializationEventHandler.class);

@Override
public boolean handleEvent(ValidationEvent event)
{
    LOG.warn("Error during XML conversion: {}", event);

    if (event.getLinkedException() instanceof NumberFormatException)
        return false;

    return true;
}

}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!