Sorry if this is obvious, but I can't find an answer. Spring 2.5, CXF
2.1, Jettison 1.0.1.
I've got a SOAP and a REST service both being configured in Spring..
REST works for XML, but I get an "Invalid JSON namespace" error if I
try to use JSON. I've tried to inject the correct Jettison mapping,
which doesn't seem to work. HOWEVER, it does seem to be doing the
right thing with the "cxf" namespace on error.
Spring config:
<util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
<entry key="http://www.acme.com/test" value="t"/>
<entry key="http://cxf.apache.org/bindings/xformat"
value="cxf"/>
</util:map>
<bean id="jsonInputFactory"
class="org.codehaus.jettison.mapped.MappedXMLInputFactory">
<constructor-arg ref="jsonNamespaceMap"/>
</bean>
<bean id="jsonOutputFactory"
class="org.codehaus.jettison.mapped.MappedXMLOutputFactory">
<constructor-arg ref="jsonNamespaceMap"/>
</bean>
<jaxrs:server id="systemEndpoint" address="/system">
<jaxrs:serviceBeans>
<ref bean="systemImpl"/>
</jaxrs:serviceBeans>
<jaxrs:properties>
<entry key="javax.xml.stream.XMLInputFactory">
<ref bean="jsonInputFactory"/>
</entry>
<entry key="javax.xml.stream.XMLOutputFactory">
<ref bean="jsonOutputFactory"/>
</entry>
</jaxrs:properties>
</jaxrs:server>
Return type;
@XmlRootElement(name = "JSONTest", namespace = "http://www.acme.com/
test")
@XmlType(name = "", propOrder = {"a", "b", "c"})
@XmlAccessorType(XmlAccessType.FIELD)
public class JSONTest {
@XmlElement
private String a;
@XmlElement
private String b;
@XmlElement
private String c;
REST impl:
@GET
@Path("/jupdate/")
public JSONTest jupdates() {
JSONTest b = new JSONTest("1", "2", "3");
return b;
}
$ curl -H "Accept: application/xml" http://localhost:8080/test/system/jupdate
<ns2:JSONTest xmlns:ns2="http://www.acme.com/test"><a>1</a><b>2</
b><c>3</c></ns2:JSONTest>
$ curl -H "Accept: application/json" http://localhost:8080/test/system/jupdate
{"cxf.XMLFault":{"cxf.faultstring":"java.lang.IllegalStateException:
Invalid JSON namespace: http:\/\/www.acme.com\/test"}}
Log file:
java.lang.IllegalStateException: Invalid JSON namespace:
http://www.acme.com/test
at
org
.codehaus
.jettison
.mapped
.MappedNamespaceConvention
.getJSONNamespace(MappedNamespaceConvention.java:151)
at
org
.codehaus
.jettison
.mapped
.MappedNamespaceConvention.createKey(MappedNamespaceConvention.java:158)
at
org
.codehaus
.jettison
.mapped
.MappedXMLStreamWriter.writeStartElement(MappedXMLStreamWriter.java:241)
at
com
.sun
.xml
.bind
.v2
.runtime
.output.XMLStreamWriterOutput.beginStartTag(XMLStreamWriterOutput.java:
113)
...
If I remove the namespace declaration from JSONTest, I get a valid
answer, but the types on the wire are really JAXB generated and I want
namespaces on them for the XML domain:
$ curl -H "Accept: application/json" http://localhost:8080/test/system/jupdate
{"JSONTest":{"a":1,"b":2,"c":3}}
--Joe