validation - JAXB-ElipseLink: Marshaller not validating -
validation - JAXB-ElipseLink: Marshaller not validating -
i eclipselink 2.3 marshaller perform validation upon marshalling. have made sure schema
correctly created schemafactory
, passing marshaller.setschema
, have registered handler via marshaller.seteventhandler()
.
the marshal result not valid acc. schema (verified in eclipse), nevertheless can see breakpoint in handleevent(validationevent event)
never hit.
i marshalling xml-fragments using marshal(object, xmlstreamwriter)
, expect marshaller perform validation on these fragments according schema passed.
anybody thought why not happening?
edit:
the validation error should occur: 2 missing attributes on element.
the element corresponds java-object contained in list<>. marshalling list using:
<xml-element java-attribute="listinstance" xml-path="listwrapperelement/listelement" type="foo.elementtype" container-type="java.util.arraylist"/>
the mapping element itself:
<java-type name="foo.elementtype" xml-accessor-type="property"> <java-attributes> // <xml-attribute> elements here </java-attributes> </java-type>
therefore attributes marshalled listwrapperelement/listelement/@attribute. 2 of these missing , not detected validation.
i have not been able reproduce issue seeing. below have tried (adapted follow blog post):
http://blog.bdoughan.com/2010/12/jaxb-and-marshalunmarshal-schema.htmlmarshaldemo (adapted blog post)
import java.io.file; import javax.xml.xmlconstants; import javax.xml.bind.jaxbcontext; import javax.xml.bind.marshaller; import javax.xml.stream.xmloutputfactory; import javax.xml.stream.xmlstreamwriter; import javax.xml.validation.schema; import javax.xml.validation.schemafactory; import org.eclipse.persistence.version; public class marshaldemo { public static void main(string[] args) throws exception { client customer = new customer(); customer.setname("jane doe"); customer.getphonenumbers().add(new phonenumber()); customer.getphonenumbers().add(new phonenumber()); customer.getphonenumbers().add(new phonenumber()); schemafactory sf = schemafactory.newinstance(xmlconstants.w3c_xml_schema_ns_uri); schema schema = sf.newschema(new file("src/blog/jaxb/validation/customer.xsd")); jaxbcontext jc = jaxbcontext.newinstance(customer.class); system.out.println(jc.getclass()); system.out.println(version.getversion()); marshaller marshaller = jc.createmarshaller(); marshaller.setproperty(marshaller.jaxb_formatted_output, true); marshaller.setschema(schema); marshaller.seteventhandler(new myvalidationeventhandler()); xmlstreamwriter xsw = xmloutputfactory.newfactory().createxmlstreamwriter(system.out); marshaller.marshal(customer, xsw); } }
output
class org.eclipse.persistence.jaxb.jaxbcontext 2.3.0 event severity: 1 message: cvc-maxlength-valid: value 'jane doe' length = '8' not facet-valid respect maxlength '5' type 'stringwithmaxsize5'. linked exception: org.eclipse.persistence.oxm.record.validatingmarshalrecord$marshalsaxparseexception: cvc-maxlength-valid: value 'jane doe' length = '8' not facet-valid respect maxlength '5' type 'stringwithmaxsize5'. locator line number: -1 column number: -1 offset: -1 object: forum8924293.customer@ef2c60 node: null url: null event severity: 1 message: cvc-type.3.1.3: value 'jane doe' of element 'name' not valid. linked exception: org.eclipse.persistence.oxm.record.validatingmarshalrecord$marshalsaxparseexception: cvc-type.3.1.3: value 'jane doe' of element 'name' not valid. locator line number: -1 column number: -1 offset: -1 object: forum8924293.customer@ef2c60 node: null url: null event severity: 1 message: cvc-complex-type.2.4.d: invalid content found starting element 'customer'. no kid element '{phone-number}' expected @ point. linked exception: org.eclipse.persistence.oxm.record.validatingmarshalrecord$marshalsaxparseexception: cvc-complex-type.2.4.d: invalid content found starting element 'customer'. no kid element '{phone-number}' expected @ point. locator line number: -1 column number: -1 offset: -1 object: forum8924293.customer@ef2c60 node: null url: null <?xml version="1.0"?><customer><name>jane doe</name><phone-number></phone-number><phone-number></phone-number><phone-number></phone-number></customer>
validation jaxb schema eclipselink moxy
Comments
Post a Comment