Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling repairing namespaces makes the serializer fail with JsonGenerationException: Unbound namespace URI '' #376

Closed
mvysny opened this issue Dec 12, 2019 · 5 comments

Comments

@mvysny
Copy link

mvysny commented Dec 12, 2019

The following code:

        val mapper: XmlMapper = XmlMapper().apply {
            enable(SerializationFeature.INDENT_OUTPUT)
            enable(ToXmlGenerator.Feature.WRITE_XML_DECLARATION)
            setSerializationInclusion(JsonInclude.Include.NON_NULL)
//            factory.xmlOutputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false)
            factory.xmlOutputFactory.setProperty(WstxOutputProperties.P_USE_DOUBLE_QUOTES_IN_XML_DECL, true)
            factory.xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false)
        }
        mapper.writeValue(file, this)

Fails with:

com.fasterxml.jackson.core.JsonGenerationException: Unbound namespace URI ''

	at com.fasterxml.jackson.dataformat.xml.util.StaxUtil.throwAsGenerationException(StaxUtil.java:47)
	at com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.writeString(ToXmlGenerator.java:613)
	at com.fasterxml.jackson.databind.ser.std.StringSerializer.serialize(StringSerializer.java:41)
	at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
	at com.fasterxml.jackson.dataformat.xml.ser.XmlBeanSerializerBase.serializeFields(XmlBeanSerializerBase.java:202)
	at com.fasterxml.jackson.dataformat.xml.ser.XmlBeanSerializer.serialize(XmlBeanSerializer.java:117)
	at com.fasterxml.jackson.dataformat.xml.ser.XmlSerializerProvider.serializeValue(XmlSerializerProvider.java:107)
	at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3905)
	at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3159)
Caused by: javax.xml.stream.XMLStreamException: Unbound namespace URI ''
	at com.ctc.wstx.sw.BaseStreamWriter.throwOutputError(BaseStreamWriter.java:1589)
	at com.ctc.wstx.sw.SimpleNsStreamWriter.writeAttribute(SimpleNsStreamWriter.java:77)
	at com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.writeString(ToXmlGenerator.java:589)
	... 72 more

woodstox-core-5.1.0.jar, jackson-dataformat-xml-2.9.9.jar.

It looks to me as if the serializer was complaining about the default empty prefix '' not being mapped, which sounds like something that should be mapped by default.

@mvysny
Copy link
Author

mvysny commented Dec 12, 2019

Workaround is to set WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE to true:

xmlMapper.factory.xmlOutputFactory.setProperty(WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE, true)

@cowtowncoder
Copy link
Member

That sounds like a problem, but what would be needed would be reproduction including value being serialized. "No namespace" case (URI of "") should definitely be handled by writers correctly

One thing I would suggest would be using a later woodstox version (I think 5.3.0 is that latest/last 5.x), although that may not solve this issue.

So: with little bit more code I might be able to figure out what is going on.

@cowtowncoder
Copy link
Member

Forgot to mention: disabling of namespace-repairing is NOT supported -- it must be left enabled.
That is by design; otherwise xml format module would need to try to deal with complexities of binding namespace URIs and so on.

Reference to WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE is helpful: this might be a bug in Woodstox (as per other issue you filed), not recognizing 2 possible values to mean essentially same thing.

@cowtowncoder
Copy link
Member

So, as per my earlier note, this may be outside of supported usage, but if I could get bit more complete reproduction (just basically POJO being serialized), I could rule it out.
This could also possibly be related to #395 that I just fixed.

@cowtowncoder
Copy link
Member

Can not reproduce currently, closing; may be reopened with reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants