Community
Participate
Working Groups
Created attachment 261184 [details] MyXMLSchema.xsd EnhanceEclipseLink Moxy Dynamic entity to work with XSD restrictions. I have created a sample XSD types that demonstrates the issue (see attached XSD). As you can see from the attached XSD, I've constructed my type hierarchy in the following manner: Base XSD type "PersonName" getting used in RegularCustomer.Name and in SecretCustomer.Name. In case of RegularCustomer.Name I want to restrict usage to only First/Middle/Last name values and for SecretCustomer.Name I want to restrict usage to only "AliasName". When I try using EclipseLink Moxy Dynamic JAXB implementation (e.g. no JAXB beans getting generated/compiled) I see the following issue, my code: import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import org.eclipse.persistence.dynamic.DynamicEntity; import org.eclipse.persistence.dynamic.DynamicType; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory; public class DynamicJAXBXMLProducer { public static void main(String[] args) throws JAXBException { DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromXSD( DynamicJAXBXMLProducer.class.getClassLoader().getResourceAsStream("MyXMLSchema.xsd"), null, null, null); DynamicEntity sCust = jaxbContext.newDynamicEntity("jaxb.dynamic.SecretCustomer"); // Lets report available property names for SecretCustomer.Name - expecting only "aliasName" DynamicType secretNameType = jaxbContext.getDynamicType("jaxb.dynamic.SecretCustomer.Name"); System.out.println("SecretCustomer.Name property names: " + secretNameType.getPropertiesNames()); // Lets report available property names for RegularCustomer.Name - expecting only "firstName, lastName, middleName" DynamicType regularNameType = jaxbContext.getDynamicType("jaxb.dynamic.RegularCustomer.Name"); System.out.println("RegularCustomer.Name property names: " + regularNameType.getPropertiesNames()); // Lets generate an invalid XML by adding forbidden firstName to SecretCustomer.Name DynamicEntity secretName = jaxbContext.newDynamicEntity("jaxb.dynamic.SecretCustomer.Name"); secretName.set("aliasName", "AliasName"); secretName.set("firstName", "fName"); // <-- This should throw an exception as "firstName" is not a valid property!!! sCust.set("name", secretName); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE); marshaller.marshal(sCust, System.out); } } The output will be: =========================== SecretCustomer.Name property names: [firstName, lastName, middleName, aliasName] RegularCustomer.Name property names: [firstName, lastName, middleName, aliasName] <?xml version="1.0" encoding="UTF-8"?> <Name> <FirstName>fName</FirstName> <AliasName>AliasName</AliasName> </Name> BUT according to the XSD restriction for SecretCustomer.Name allowed property name is only "aliasName" and for RegularCustomer.Name only firstName, lastName, middleName Can this be fixed in MOXy to generate a proper implementation (at least for dynamic entity) as per XSD schema restrictions?
See StackOverflow for this: http://stackoverflow.com/questions/36780294/eclipselink-moxy-dynamic-jaxb-strange-behavior-for-standard-xsd-restrictions
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink