1

MOXyを使用して比較的単純なXMLドキュメントをアンマーシャリングしていますが、動作に一貫性がありません。このドキュメントは、基本情報(名前と日付)とそれに続くレコードのリストを含む2つの要素で構成されています。問題は、名前と日付が毎回正しくアンマーシャリングされていることですが、レコードを取得しないことがよくあります(これは、同じ静的データを繰り返し使用する単体テストで検証されていますが、予測可能性が観察されずに合格および不合格になっています)。すべてのロギングとアサーションは、6つのレコードすべてを取得する場合と、0を取得する場合(他の数値は取得しない場合)を除いて、すべてが良好に見えることを検証します。この一貫性のない振る舞いは、私にはまったく意味がありません、何かアイデアはありますか?適切なアンマーシャリングを保証する注釈などがありませんか?

eclipselinkライブラリのいくつかの異なるバージョンを試しましたが、すべて同じ結果になりました(現在、eclipselink mavenリポジトリから2.2.0をロードしています)。

レポートクラス

package com.company.report_parser.model;

import org.eclipse.persistence.oxm.annotations.XmlPath;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;

@XmlRootElement(name="feedback")
public class SpecificAggregateReport extends AggregateReport {
    @XmlPath("submitter/org_name/text()")
    protected void setPartnerName(String partnerName) {
        super.setPartnerName(partnerName);
    }

    @XmlPath("date_range/end/text()")
    protected void setDate(String date) {
        super.setDate(date);
    }

    public List<AggregateRecord> getRecords() {
        return super.getRecords();
    }
    @XmlPath("authstats/record")
    @XmlElement(type=SpecificAggregateRecord.class) // This is the element class which implements the AggregateRecord Interface used in the List
    protected void setRecords(List<AggregateRecord> records) {
        super.setRecords(records);
    }
}

レコードクラス パッケージcom.company.report_parser.model;

import org.eclipse.persistence.oxm.annotations.XmlPath;

public class SpecificAggregateRecord extends AggregateRecord {
    @XmlPath("row/@source_ip")
    protected void setSourceIp(String sourceIp) {
        super.setSourceIp(sourceIp);
    }

    @XmlPath("row/@count")
    protected void setCount(String count) {
        super.setCount(count);
    }

    @XmlPath("identities/@envelope_from")
    protected void setSmtpFrom(String envelope_from) {
        super.setSmtpFrom(envelope_from);
    }

    @XmlPath("identities/@header_from")
    protected void setHeaderFromDomain(String header_from) {
        super.setHeaderFromDomain(header_from);
    }

    @XmlPath("auth_results/dkim/@result")
    protected void setDkimResult(String result) {
        super.setDkimResult(result);
    }

    @XmlPath("auth_results/dkim/@d")
    protected void setDkimDomain(String d) {
        super.setDkimDomain(d);
    }

    @XmlPath("auth_results/spf/@result")
    protected void setSpfResult(String result) {
        super.setSpfResult(result);
    }
}

サンプルデータ

<?xml version="1.0" encoding="UTF-8" ?>
<feedback>
  <submitter>
    <org_name>specific</org_name>
    <email>support@specific.com</email>
  </submitter>
  <date_range>
    <begin>20110511</begin>
    <end>20110511</end>
  </date_range>
  <report_id>682417472261065178</report_id>
  <authstats>
    <record>
      <row source_ip="184.106.220.108" count="8" policy_domain="test.net" policy="none" action_taken="none" />
      <identities envelope_from="test.net" header_from="test.net" />
      <auth_results>
        <dkim result="neutral" d="test.net" />
        <spf domain="test.net" identity="spf_envelope_from" result="pass" />
      </auth_results>
    </record>
    <record>
      <row source_ip="50.56.76.41" count="6" policy_domain="test.net" policy="none" action_taken="none" />
      <identities envelope_from="test.net" header_from="test.net" />
      <auth_results>
        <dkim result="neutral" d="test.net" />
        <spf domain="test.net" identity="spf_envelope_from" result="softfail" />
      </auth_results>
    </record>
    <record>
      <row source_ip="50.56.76.41" count="6" policy_domain="test.net" policy="none" action_taken="none" />
      <identities envelope_from="test.net" header_from="test.net" />
      <auth_results>
        <dkim result="none" d="" />
        <spf domain="test.net" identity="spf_envelope_from" result="softfail" />
      </auth_results>
    </record>
    <record>
      <row source_ip="184.106.220.108" count="6" policy_domain="test.net" policy="none" action_taken="none" />
      <identities envelope_from="test.net" header_from="test.net" />
      <auth_results>
        <dkim result="pass" d="test.net" />
        <spf domain="test.net" identity="spf_envelope_from" result="pass" />
      </auth_results>
    </record>
    <record>
      <row source_ip="50.56.76.41" count="8" policy_domain="test.net" policy="none" action_taken="none" />
      <identities envelope_from="test.net" header_from="test.net" />
      <auth_results>
        <dkim result="pass" d="test.net" />
        <spf domain="test.net" identity="spf_envelope_from" result="softfail" />
      </auth_results>
    </record>
    <record>
      <row source_ip="184.106.220.108" count="6" policy_domain="test.net" policy="none" action_taken="none" />
      <identities envelope_from="test.net" header_from="test.net" />
      <auth_results>
        <dkim result="none" d="" />
        <spf domain="test.net" identity="spf_envelope_from" result="pass" />
      </auth_results>
    </record>
  </authstats>
</feedback>
4

1 に答える 1

1

問題

一貫性のない動作は、子クラスでプロパティがオーバーライドされていることが原因です。MOXyは、親クラスと子クラスの両方のプロパティがマップされていると見なし、処理された順序に応じて、いずれかの動作が表示されます。

解決策#1

親プロパティがマップされていないことをMOXyに通知する必要があります。これは@XmlAccessorType(XmlAccessType.NONE)AggregateRecordおよびAggregateReportクラスで指定することで実行できます。

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAccessType;

@XmlAccessorType(XmlAccessType.NONE)
public class AggregateRecord {
   ...
}

次に、クラスで指定@XmlAccessorType(XmlAccessType.PROPERTY)します。SpecificAggregateRecordSpecificAggregateReport

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAccessType;

@XmlAccessorType(XmlAccessType.PROPERTY)
public class SpecificAggregateRecord extends AggregateRecord {

解決策#2

マッピングを適用する目的でのみサブクラスのアクセサーをオーバーライドする場合は、代わりにMOXyの外部マッピングファイルの使用を検討することをお勧めします。以下に例を示します。

このオプションの検討に興味がある場合はお知らせください。

于 2011-05-24T14:14:54.527 に答える