FasterXML / FasterXML/jackson-dataformat-xml
`XmlMapper` output not well-formed when Object keys use invalid XML name characters
- Lenguaje dominante
- Java
- Estrellas
- 631
- Forks
- 247
- Merge medio
- 7 d 9 h
- PR fusionados (30 d)
- 13
Descripción
I've been working with a lot of web APIs and converting the JSON to XML using XmlMapper. It generally works great, but I have an example that creates invalid XML. I am using the latest version of Jackson (2.13.1).
When you call this API you get the attached JSON output.
`https://world.openfoodfacts.org/api/v0/product/7622300315733.json`
The Jackson pretty-printer has no problem indenting this nicely.
[BadXmlFromJson.zip](https://github.com/FasterXML/jackson-dataformat-xml/files/7856593/BadXmlFromJson.zip)
After converting it to XML (also in the attached ZIP) you get some issues that prevent Xerces or Saxon from parsing it:
1. Namespace prefixes are not declared
2. Some elements are not well formed
For example, at line 48 you see this:
`12315`
and at line 653 you see this: `<1>` which is an error because XML names must start with a letter or underscore.
I'm using XmlMapper like this:
XmlMapper xmlMapper = new XmlMapper();
return xmlMapper.writeValueAsString(jsonTree);
I can't find any features in FromXmlParser.Feature or ToXmlGenerator.Feature that apply to either of these issues.
Is there another way to configure XmlMapper or is this a bug?
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza reproduciendo la conversión con XmlMapper y el JSON de Open Food Facts enlazado o BadXmlFromJson.zip. Compara el XML generado con el parsing de Xerces o Saxon y, después, inspecciona las opciones disponibles de FromXmlParser.Feature y ToXmlGenerator.Feature. Se considera terminado cuando la salida está bien formada para claves como agribalyse_proxy_food_code:en y 1, con los prefijos de espacio de nombres gestionados correctamente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- java
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100