You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by jmdev <jh...@yahoo.com> on 2009/04/29 21:16:11 UTC

Setting (un)marshaller options for JAXB using CXF?

I am looking to be able to add behaviors to some of my JAXB generated
classes.  The JAXB documentation seems to suggest that I need to set a
property on the (un)marshaller class 

(i.e.

Unmarshaller u = context.createUnmarshaller();
u.setProperty("com.sun.xml.bind.ObjectFactory",new ObjectFactoryEx());
PersonEx p = (PersonEx)u.unmarshal(new StringReader("<person />"));

)

Is it possible to get access to the (un)marshaller classes in the course of
CXF web service call so that I can set properties?  If so, could you provide
a quick example of the method call(s)?

Thanks!
-- 
View this message in context: http://www.nabble.com/Setting-%28un%29marshaller-options-for-JAXB-using-CXF--tp23300347p23300347.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Setting (un)marshaller options for JAXB using CXF?

Posted by Daniel Kulp <dk...@apache.org>.
On Wed April 29 2009 3:16:11 pm jmdev wrote:
> I am looking to be able to add behaviors to some of my JAXB generated
> classes.  The JAXB documentation seems to suggest that I need to set a
> property on the (un)marshaller class
>
> (i.e.
>
> Unmarshaller u = context.createUnmarshaller();
> u.setProperty("com.sun.xml.bind.ObjectFactory",new ObjectFactoryEx());
> PersonEx p = (PersonEx)u.unmarshal(new StringReader("<person />"));
>
> )
>
> Is it possible to get access to the (un)marshaller classes in the course of
> CXF web service call so that I can set properties?  If so, could you
> provide a quick example of the method call(s)?
>
> Thanks!

I don't think there is access to the actual unmarshaller/marshallers.   
However, the JAXBDataBinding object itself has maps for properties that are 
then copied over into any marshaller/unmarshaller that it creates.    If you 
look on the page at:
http://cwiki.apache.org/CXF20DOC/jaxb.html
it shows some starting points for how to configure the JAXB databinding.   
Looking into the JAXBDataBinding class, there are fields for:
    private Map<String, Object> contextProperties;
    private Map<String, Object> marshallerProperties;
    private Map<String, Object> unmarshallerProperties;
    private Unmarshaller.Listener unmarshallerListener;
    private Marshaller.Listener marshallerListener;
    private ValidationEventHandler validationEventHandler;

so those would be some of the properties that you could configure to do 
whatever customization that you may need.


-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog