users@jersey.java.net

Re: [Jersey] Is it always required to use xml2Ns() method?

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Thu, 09 Jul 2009 14:18:56 +0200

On Thu, Jul 09, 2009 at 05:33:52PM +0530, Naresh wrote:
> Hi,
>
> I was playing around the new JSON Namespace Support feature.
> Seems that when using the "mapped jettison" notation with JAXB beans
> having defined namespaces, Jersey throws the following exception, if the
> xml2Ns() method is not used:
> ------------------------------------------------------------------
> java.lang.IllegalStateException: Invalid JSON namespace:
> urn:oasis:names:specification:ubl:schema:xsd:Order-2
> at
> org.codehaus.jettison.mapped.MappedNamespaceConvention.getJSONNamespace(MappedNamespaceConvention.java:182)
> at
> org.codehaus.jettison.mapped.MappedNamespaceConvention.createKey(MappedNamespaceConvention.java:189)
> at
> org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeStartElement(MappedXMLStreamWriter.java:244)
> at
> com.sun.xml.bind.v2.runtime.output.XMLStreamWriterOutput.beginStartTag(XMLStreamWriterOutput.java:113)
> at
> com.sun.xml.bind.v2.runtime.output.XmlOutputAbstractImpl.beginStartTag(XmlOutputAbstractImpl.java:98)
> at
> com.sun.xml.bind.v2.runtime.output.NamespaceContextImpl$Element.startElement(NamespaceContextImpl.java:491)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.endNamespaceDecls(XMLSerializer.java:287)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:590)
> at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:320)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
> at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315)
> at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:172)
> at
> com.sun.jersey.json.impl.BaseJSONMarshaller.marshallToJSON(BaseJSONMarshaller.java:98)
> ------------------------------------------------------------------
>
> However, for other notations like 'mapped' and 'natural' it just
> ignores the namespaces if xml2Ns() method is not called.

For the natural notation, there is no such option as xml2Ns,
as namespace prefixes are being omitted there on purpose.
For the internal mapped notation, unmarshalling would break
without explicit namespace configuration, but marshalling would work
like you described.

>
> Is it an expected behavior for the mapped jettison notation?

I guess so. All jersey does is it defers to jettison in this regard,
so you would need to ask at a jettison forum.

~Jakub

>
> Thanks,
> Naresh
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>