Using `@XmlAttribute` for property with non-scalar type prevents serialization as attribute for other properties

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

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

評価

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

調査の方向性

Start with the Bug2.main reproducer and run the two XmlMapper serialization cases shown in the issue. Trace how the JAXB @XmlAttribute annotations are handled for the non-scalar Bean field, then verify that the behavior for start, bean, and end matches an explicitly agreed outcome and add a regression test if the project’s test location is identified.

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

説明

has-failing-test

Look at the last line of this class.
Incorrect using @XmlAttribute for a bean serialization breaks a serialization of other properties.
I excepted to see an error or bean value as an attribute value.

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

public class Bug2 {

    @XmlRootElement(name = "bean")
    public static class Bean {

    }

    @XmlRootElement(name = "root")
    public static class Container {
        @XmlAttribute(name = "start")
        public String start;

        @XmlAttribute(name = "bean")
        public Bean bean;

        @XmlAttribute(name = "end")
        public String end;
    }

    public static void main(String[] args) throws JsonProcessingException {
        XmlMapper xmlMapper = new XmlMapper();
        xmlMapper.registerModule(new JaxbAnnotationModule());
        xmlMapper.registerModule(new JacksonXmlModule());

        Container container = new Container();
        container.start = "!start";
        container.end = "!end";
        System.out.println(xmlMapper.writeValueAsString(container)); // print <root xmlns="" start="!start" end="!end"></root>

        Bean bean = new Bean();
        container.bean = bean;
        System.out.println(xmlMapper.writeValueAsString(container)); // print <root xmlns="" start="!start"><bean></bean><end>!end</end></root>
    }
}

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