cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From K Fung <>
Subject JSON ignore namespace behavior in IgnoreContentJettisonWriter
Date Sun, 09 Oct 2011 20:49:41 GMT
Hi all,

(not sure if this belongs in cxf-dev or cxf-user; given the level of code
detail here though, I'm thinking cxf-dev but feel free to redirect if

I'm looking to get some advice on how to fix a WebApplicationException /
IllegalStateException inside CXF's JSON code. I've got a solution in mind
for the CXF code but I'm not an expert in JSON so I'm wondering if my code
is incorrect or if this is truely a bug in CXF?

In my scenario, CXF is generating the following exception:

WARNING: WebApplicationException has been caught : Invalid JSON namespace:
 even when I have JSONProvider.setIgnoreNamespaces to be true.

The XML output is fine:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <Library xmlns:ns2="">
 <ns2:Book xmlns:xsi=""

However, the JSON output fails with HTTP 500 due to the above

Looking at the source code, I can see that it's failing in

public void writeAttribute(String prefix, String uri,
                           String local, String value) throws
XMLStreamException {
    if (!writeXsiType && "type".equals(local) && "xsi".equals(prefix)) {
    super.writeAttribute(prefix, uri, local, value);


At the time of invocation for IgnoreContentJettisonWriter.writeAttribute, we
have the following values:

prefix = xsi
uri =
 local = nil
value = true
writeXsiType = false

Given these values, we still call super.writeAttribute which then
consequently bombs with the IllegalStateException.

To me, the naive solution in this scenario would be the following: If
writeXsiType is set to false and local != "type", super.writeAttribute
should be called with a null value for uri. With this change, the JSON
output looks like the following:


What are your thoughts? Would there be any issues with reading this JSON?


Appendix A: JAXB Classes

@XmlType(name = "", propOrder = {"book"})
@XmlRootElement(name = "Library")
public class Library {

    @XmlElement(name = "Book", required = true)
    protected List<Book> book;

    public List<Book> getBook() {
        if ( == null) {
   = new ArrayList<Book>();

    public void setBook(List<Book> l) { = l;


@XmlType(name="Book", propOrder={"book"})
public class Book

  @XmlElement(name="Book", namespace="",
required=true, nillable=true)
  protected String book;

  public String getBook()

  public void setBook(String value)
  { = value;

Appendix B: Invocation Example

    public Library getBook() throws JAXBException {

        final Book john = new Book();

        Library lib = new Library();
        List<Book> l = new ArrayList<Book>(1);

        return lib;

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message