Skip to content

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

Closed
@mvysny

Description

@mvysny

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions