Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7080897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:51:06+00:00 2026-05-28T06:51:06+00:00

I would like my Eclipselink 2.3 Marshaller to perform validation upon marshalling. I have

  • 0

I would like my Eclipselink 2.3 Marshaller to perform validation upon marshalling.
I have made sure that the Schema is correctly created by a SchemaFactory, i am passing it to Marshaller.setSchema and i have registered a handler via Marshaller.setEventHandler().

The marshal result is clearly not valid acc. to its Schema (verified in Eclipse), nevertheless i can see that my breakpoint in handleEvent(ValidationEvent event) is never hit.

I am marshalling XML-Fragments using marshal(Object, XMLStreamWriter) and would expect the Marshaller to perform validation on these fragments according to the Schema i passed.

Anybody any idea why this is not happening?

EDIT:

The Validation error that should occur: 2 missing attributes on an element.

The element corresponds to a Java-Object that is contained in a List<>. I am marshalling the List using:

<xml-element java-attribute="listInstance" xml-path="ListWrapperElement/ListElement" type="foo.ElementType" container-type="java.util.ArrayList"/>

The mapping for the element itself:

<java-type name="foo.ElementType" xml-accessor-type="PROPERTY">
    <java-attributes>
        // just <xml-attribute> elements here
    </java-attributes>
</java-type>

Therefore all attributes are marshalled to ListWrapperElement/ListElement/@attribute.
2 of these are missing and not detected by validation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:51:06+00:00Added an answer on May 28, 2026 at 6:51 am

    I have not been able to reproduce the issue that you are seeing. Below is what I have tried (adapted from the follow blog post):

    • http://blog.bdoughan.com/2010/12/jaxb-and-marshalunmarshal-schema.html

    MarshalDemo (adapted from 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 {
            Customer 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' with length = '8' is not facet-valid with respect to maxLength '5' for type 'stringWithMaxSize5'.
    LINKED EXCEPTION:  org.eclipse.persistence.oxm.record.ValidatingMarshalRecord$MarshalSAXParseException: cvc-maxLength-valid: Value 'Jane Doe' with length = '8' is not facet-valid with respect to maxLength '5' for 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: The value 'Jane Doe' of element 'name' is not valid.
    LINKED EXCEPTION:  org.eclipse.persistence.oxm.record.ValidatingMarshalRecord$MarshalSAXParseException: cvc-type.3.1.3: The value 'Jane Doe' of element 'name' is 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 was found starting with element 'customer'. No child element '{phone-number}' is expected at this point.
    LINKED EXCEPTION:  org.eclipse.persistence.oxm.record.ValidatingMarshalRecord$MarshalSAXParseException: cvc-complex-type.2.4.d: Invalid content was found starting with element 'customer'. No child element '{phone-number}' is expected at this 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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading about JPA and EJB3 and would like to confirm that
I have a running web service (using EclipseLink as JPA provider) and would like
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to have a reference for the pros and cons of using
I would like to use a language that I am familiar with - Java,
I would like to be able to swap my JPA implementation between EclipseLink &
I would like to check in a JAX-RS webservice request that valid XML was
I have a standalone Java application that uses EclipseLink 2.0.1. It is configured by
would like to put fieldSets side-by-side on my Edit page because I have so
would like to know how can this be implemented in Joomla. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.