簡體   English   中英

Spring Jaxb2Marshaller驗證不起作用

[英]Spring Jaxb2Marshaller validation doesn't work

如何使用Jaxb2Marshaller對架構啟用驗證? 下面的示例中,如果DateTime標記錯誤(應與T“ 2015-09-09 T 16:56:39”一起使用),則不會出現異常,解組器只會返回null的模型。

        schema: <xs:element name="ExecutionTime" minOccurs="0" maxOccurs="1"
                type="xs:dateTime" />

        tag example   <ExecutionTime>2015-09-09 16:56:39</ExecutionTime>



            Jaxb2Marshaller marshaller = null;
            marshaller = new Jaxb2Marshaller();
            marshaller.setContextPath(contextPath);
            ClassPathResource schemaResource = new   ClassPathResource(classpathXSD);
            marshaller.setSchema(schemaResource);
            marshaller.setMappedClass(Entity.class);

            marshaller.unmarshal(stringSource)
..
marshaller.setValidationEventHandler(validationEvent -> processEvent(validationEvent));
..

因此,我發現,如果您指定了此選項,並且您的XML對於XSD而言具有無效數據,那么您實際上將開始獲取驗證錯誤事件和異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM