Each list element is wrapped into an extra tag with the name of the list property (RFE: combine type id, property name)

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

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

評価

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

調査の方向性

まず、示されている ObjectMapper の設定と Jackson のバージョンを使って、XJC で生成された Body クラスから生成される XML を再現します。追加された transactionAndErrorAndErrorEmail ラッパーを期待される XML と比較し、その後、リスト要素のラッピングを決定する mapper の動作を特定します。混在したリストが、追加のプロパティラッパーなしで transaction 要素と error 要素として直接シリアライズされれば完了です。

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

説明

I am implementing a Java class for calling an external API with uses XML as data format. The API provider provides for each Endpoint the corresponding XML schema. I used the XJC compiler to create schematically compliant Java classes.
Now I have the problem, that the object mapper does wrap list elements into extra tags and therefore, the API call is rejected.

XML schema:

<xs:element name="body" minOccurs="0">
  <xs:complexType>
    <xs:sequence minOccurs="1" maxOccurs="unbounded">
      <xs:element name="transaction" minOccurs="0">...</xs:element>
      <xs:element name="error" type="error" minOccurs="0"/>
      <xs:element type="xs:string" name="errorEmail" minOccurs="0">...</xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Java class:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "transactionAndErrorAndErrorEmail"
})
public static class Body {
    @XmlElements({
        @XmlElement(name = "transaction", type = Transaction.class),
        @XmlElement(name = "error", type = Error.class),
        @XmlElement(name = "errorEmail", type = String.class)
    })
    protected List<Object> transactionAndErrorAndErrorEmail;
    ...
}

Object Mapper Configuration:

 final ObjectMapper objectMapper = Jackson2ObjectMapperBuilder
                .xml()
                .modules(new JaxbAnnotationModule())
                .defaultUseWrapper(false)
                .serializationInclusion(JsonInclude.Include.NON_NULL)
                .build();

Generated XML:

<body >
  <transactionAndErrorAndErrorEmail>
    <transaction>
      ...
    </transaction>
  </transactionAndErrorAndErrorEmail>
  <transactionAndErrorAndErrorEmail>
    <error>
      ...
    </error>
  </transactionAndErrorAndErrorEmail>
</body>

What I expected:

<body >
    <transaction>
      ...
    </transaction>
    <error>
      ...
    </error>
</body>

I am working with Jackson version 2.8.8, but I tested it also with version 2.9.0.pr2, but without success.

主要言語
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 を短くまとめたダイジェスト。