users@jaxb.java.net

Re: JAXB - Automatic creation of mandatory children

From: kr vijay <sagivijay_at_yahoo.com>
Date: Tue, 21 Sep 2004 05:31:59 -0700 (PDT)

Hi,
I have a wrapper class that has methods for
marshaling/unmarshalling. These are the methods in it.
  public Rbml unmarshal() throws java.lang.Exception {
    Unmarshaller u = jc.createUnmarshaller();
        u.setEventHandler(new ValidationEventHandler()
        {
                public boolean handleEvent(ValidationEvent event)
                {
                        return true;
                }
        });

    return (Rbml)u.unmarshal(new
FileInputStream(inputFilename));
  }

  public void marshal(Rbml rbml) throws
java.lang.Exception {
    Marshaller m = jc.createMarshaller();
        m.setEventHandler(new ValidationEventHandler()
        {
                public boolean handleEvent(ValidationEvent event)
                {
                        return true;
                }
        });

    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,new
Boolean(true));
    m.marshal(rbml, new
FileOutputStream(outputFilename));
  }


--- Aleksei Valikov <valikov_at_gmx.net> wrote:

> Hi.
>
> > I am doing the following after setting the
> > validationHandler for both the marshaller and
> > unmarshaller:
> >
> > ObjectFactory objectFactory = new
> ObjectFactory();
> > ConfigurationMatch configurationMatch =
> >
>
(ConfigurationMatch)objectFactory.newInstance(com.cisco.paws.ta.ConfigurationMatch.class);
> >
> > I then add the configurationMatch object to its
> > parent's list (The parent can contain multiple
> > configurationMatch elements)
> >
> > I am then marshalling the root when I get the
> > following exception. Similarly, I get an exception
> if
> > I try to unmarshal an invalid XML. Is this related
> to
> > the bug you posted earlier. If so, when is a fix
> > expected for this. Until then, do I have to
> manually
> > create and set the mandatory children?
>
> No, this is not related to the problem I mentioned.
>
> Might help if you post your
> marshalling/unmarshalling code. Your stack
> trace shows that you have not replaced the default
> validation handler:
>
> > DefaultValidationEventHandler: [ERROR]: a required
> > field "Name" is missing an ob
> > ject
> > Location: obj:
> >
>
com.cisco.paws.ta.impl.ConfigurationMatchImpl_at_1682a53
> > Marshal Exception
> javax.xml.bind.ValidationException
> > - with linked exception:
> >
>
[com.sun.xml.bind.serializer.AbortSerializationException:
> > a required field "Name
> > " is missing an object]
>
> Bye.
> /lexi
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail:
> users-help_at_jaxb.dev.java.net
>
>



                
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net