`XmlMapper` output not well-formed when Object keys use invalid XML name characters

オープン
#511 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
backend

調査の方向性

まず、XmlMapper とリンクされた Open Food Facts JSON または BadXmlFromJson.zip を使って変換を再現します。生成された XML を Xerces または Saxon でのパース結果と比較し、その後、利用可能な FromXmlParser.Feature および ToXmlGenerator.Feature のオプションを調べます。agribalyse_proxy_food_code:en や 1 のようなキーに対して、名前空間プレフィックスが正しく処理された整形式の出力になることが完了の条件です。

索引モデルが issue の本文から書いたものです。

説明

test-needed

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

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:
<agribalyse_proxy_food_code:en>12315</agribalyse_proxy_food_code:en>

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?

主要言語
Java
スター
636
フォーク
250
平均マージ
7時間 10分
マージ済み PR(30日)
8

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

FasterXML/jackson-dataformat-xml のほかの issue

FasterXML/jackson-dataformat-xml の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。