Jaxb,类有两个同名属性

2024-04-05

使用 Jaxb (jaxb-impl-2.1.12),UI 尝试读取XML 文件 http://www.copypastecode.com/75029/

XML 文件中只有少数元素是有趣的,因此我想跳过大部分元素。

我正在尝试读取的 XML:

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2010 rel. 3 sp1 (http://www.altova.com)-->
<flx:ModeleREP xsi:schemaLocation="urn:test:mod_rep.xsd mod_rep.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flx="urn:test:mod_rep.xsd">
<flx:DocumentHeader>
    <flx:Identification v="04489"/>
</flx:DocumentHeader>
<flx:TimeSeries>
    <flx:Identification v="test1a"/>
    <flx:BusinessType v="A01"/>
    <flx:Product v="123a"/>
    <flx:ResourceObject codingScheme="N" v="testa"/>
    <flx:Period>
        <flx:TimeInterval v="2011-07-02T00:00/2011-07-16T00:00"/>
        <flx:Resolution v="PT2H"/>
        <flx:Pt>
            <flx:P v="1"/>
            <flx:Q unitCode="String" v="1.0"/>
            <flx:A currencyIdentifier="String" v="195.0"/>
        </flx:Pt>
    </flx:Period>
</flx:TimeSeries>
<flx:TimeSeries>
    <flx:Identification v="test2a"/>
    <flx:BusinessType v="A01"/>
    <flx:Product v="a123b"/>
    <flx:ResourceObject codingScheme="N" v="test2"/>
    <flx:Period>
        <flx:TimeInterval v="2011-07-02T00:00/2011-07-16T00:00"/>
        <flx:Resolution v="PT2H"/>
        <flx:Pt>
            <flx:P v="1"/>
            <flx:Q unitCode="String" v="1.0"/>
            <flx:A currencyIdentifier="String" v="195.0"/>
        </flx:Pt>
        <flx:Pt>
            <flx:P v="2"/>
            <flx:Q unitCode="String" v="1.0"/>
            <flx:A currencyIdentifier="String" v="195.0"/>
        </flx:Pt>
    </flx:Period>
</flx:TimeSeries>
</flx:ModeleREP>

my class

@XmlRootElement(name="ModeleREP", namespace="urn:test:mod_rep.xsd")
public class ModeleREP {

  @XmlElement(name="TimeSeries")
  protected List<TimeSeries> timeSeries;

  public List<TimeSeries> getTimeSeries() {
  if (this.timeSeries == null) {
      this.timeSeries = new ArrayList<TimeSeries>();
  }
  return this.timeSeries;
  }

  public void setTimeSeries(List<TimeSeries> timeSeries) {
  this.timeSeries = timeSeries;
  }

}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "TimeSeries")
public class TimeSeries {

@XmlElement(name="ResourceObject")
protected RessourceObject resourceObject;

@XmlElement(name = "Period")
protected Period period;

public RessourceObject getResourceObject() {
    return this.resourceObject;
}

public void setResourceObject(RessourceObject resourceObject) {
    this.resourceObject = resourceObject;
}

public Period getPeriod() {
    return this.period;
}

public void setPeriod(Period period) {
    this.period = period;
}

}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "ResourceObject")

public class RessourceObject {
@XmlAttribute(name = "codingScheme")
protected String codingScheme;

@XmlAttribute(name = "v")
protected String v;

public String getCodingScheme() {
    return this.codingScheme;
}

public void setCodingScheme(String codingScheme) {
    this.codingScheme = codingScheme;
}

public String getV() {
    return this.v;
}

public void setV(String v) {
    this.v = v;
}
}

@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Period")
public class Period {

@XmlElement(name = "TimeInterval")
protected TimeInterval timeInterval;

@XmlElement(name = "Pt")
protected List<Pt> pt;

public TimeInterval getTimeInterval() {
    return this.timeInterval;
}

public void setTimeInterval(TimeInterval timeInterval) {
    this.timeInterval = timeInterval;
}

public List<Pt> getPt() {
    if (this.pt == null) {
    this.pt = new ArrayList<Pt>();
    }
    return this.pt;
}

public void setPt(List<Pt> pt) {
    this.pt=pt;
}

}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "TimeInterval")
public class TimeInterval {

@XmlAttribute(name = "v")
private String timeIntervalPeriod;

public String getTimeIntervalPeriod() {
    return this.timeIntervalPeriod;
}

public void setTimeIntervalPeriod(String timeIntervalPeriod) {
    this.timeIntervalPeriod = timeIntervalPeriod;
}

}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Pt")
public class Pt {

@XmlElement(name = "P")
protected P p;

@XmlElement(name = "A")
protected A a;

public P getP() {
    return this.p;
}

public void setP(P p) {
    this.p = p;
}

public A getA() {
    return this.a;
}

public void setA(A a) {
    this.a = a;
}
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "P")
public class P {
@XmlAttribute(name = "v")
protected String position;


public String getPosition(){
    return this.position;
}

public void setPosition(String position){
    this.position=position;
}
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "A")
public class A {
@XmlAttribute(name = "v")
protected String calculatedAmount;

public String getCalculatedAmount() {
    return this.calculatedAmount;
}

public void setCalculatedAmount(String calculatedAmount) {
    this.calculatedAmount = calculatedAmount;
}
}

当我尝试读取 XML 文件时,出现以下错误:

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "timeSeries"
    this problem is related to the following location:
        at public java.util.List testjaxp.ModeleREP.getTimeSeries()
        at testjaxp.ModeleREP
    this problem is related to the following location:
        at protected java.util.List testjaxp.ModeleREP.timeSeries
        at testjaxp.ModeleREP

我不明白这个错误。有时,当我检查对象时,timeSeries 为空。

如何修复此错误/防止 timeSeries 返回 null?


当我遇到这个问题时,我设置了这些属性。设置其中之一或两者可能会解决您的问题:

@XmlRootElement(name="yourRootElementName")
@XmlAccessorType(XmlAccessType.FIELD)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Jaxb,类有两个同名属性 的相关文章

随机推荐

  • 如何在不停止应用程序的情况下延迟功能

    void sendCommand float t char cmd std clock t endwait double endwait clock t CLOCKS PER SEC while clock lt endwait if cl
  • XMLHttpRequest() 未被识别为 IsAjaxRequest?

    为了在 Ajax 请求会话超时时将用户重定向到登录页面 我实现了以下自定义属性 与未授权请求相关的代码如下 protected override void HandleUnauthorizedRequest AuthorizationCon
  • 如何让你的主窗口在 Tkinter 成功登录后出现(PYTHON 3.6

    这是带有默认用户名和密码的用户界面 但成功登录后需要出现主用户界面 挑战 当您正确输入用户名和密码时 主窗口不会打开 而是当您单击取消或关闭按钮时 它会打开 寻找解决方案 使用默认密码和用户名成功登录后应出现主窗口 from tkinter
  • 使用单一设置在所有 Windows 窗体中设置相同的背景

    我的 C 项目中有 40 个 Windows 窗体 我必须在所有表单中设置相同的背景 是否有任何选项或设置可以在单个设置中执行此操作 您可以创建基本表单并为其设置背景 其他表单继承自基本表单 class baseForm Form void
  • 使用cloudformation模板在cloudfront中添加Lambda@edge includebody字段?

    我正在尝试添加Lambda Edge使用 cloudformation 在 cloudfront 中进行关联 按照aws docs https docs aws amazon com AWSCloudFormation latest Use
  • 无法在 Ubuntu 20.04 上安装 ROS Melodic

    我正在尝试使用这些命令在 Ubuntu 20 04 上安装 ROS Melodic sudo sh c echo deb http packages ros org ros ubuntu lsb release sc main gt etc
  • 强制浏览器忽略缓存

    我的代码裁剪一张照片 裁剪后的照片会不断替换 但浏览器只会加载第一个裁剪的照片 我已经在网上搜索过 但没有任何效果 我已将随机字符串添加到 php new jpg time t 但这会阻止保存裁剪后的图像 我已经包括了 但浏览器仍然从缓存加
  • 根据因子使用不同的比例作为填充

    cnt 100 df lt data frame x c rnorm cnt mean 3 rnorm cnt mean 0 y rnorm 2 cnt g rep 0 1 each cnt ggplot df aes x y color
  • 多值 amChart 是否可以只显示一个 Y 轴?

    我有一个多值 AmChart 我在其中发送动态值并且按预期工作 但由于我动态发送百分比值的值 因此不需要为所有行单独使用 Y 轴 对于所有线来说 只有一个 y 轴就足够了 我可以禁用显示的 y 轴 并且还创建了单个 y 轴 静态 y 轴 但
  • Git 和二进制文件历史记录

    This is a follow up on some similar answered questions about git handling binary files https stackoverflow com questions
  • Flutter:如何根据设备的屏幕尺寸调整文本大小

    在 flutter 中 如何根据设备屏幕尺寸调整应用程序中的文本大小 该应用程序用于阅读文本 我需要用户随着设备尺寸的增加看到更大的文本 并设置最大可能的尺寸 我知道的一种方法就是这样做 Text Some text here style
  • 如何创建Windows服务来运行powershell脚本?

    我有无限循环 PowerShell 测试目的 脚本 我想将其作为 Windows Server 2008 R2 标准 中的服务运行 我使用以下命令来创建 Windows 服务 sc exe create My PS1Service binP
  • C 中是否有一个函数与 Python 中的 raw_input 功能相同?

    有没有一个C函数可以做同样的事情raw input在Python中 in Python x raw input Message Here 我怎样才能用C写出这样的东西 Update 我做了这个 但出现错误 include
  • Laravel 5.1:将数据传递给 View Composer

    我在 Laravel 5 1 中使用视图编辑器 很好 但是如何将参数传递给视图编辑器 就我而言 我将周信息 上周 当前 下周 包括日期 发送到我的视图中 并使用 de viewcomposer 当前星期是可变的 不仅来自 url 还来自控制
  • 在活动模式中使用 typeof<_>

    给出以下人为的活动模式 let TypeDef typeDef Type value obj if obj ReferenceEquals value null then None else let typ value GetType if
  • 编写更短的代码/算法是否更高效(性能)?

    在网站上看到代码高尔夫琐事后 很明显 人们试图找到在字符 行和总大小方面尽可能短的代码和算法的编写方法 即使这意味着编写如下内容 Code by job Topic Code Golf Collatz Conjecture n input
  • 如何构建 iPhone Xcode 项目?

    建立组 文件夹的好方法是什么 我已经尝试通过功能 功能加模型等的用户界面 与一个共同的组 我也尝试过UI 模型等 前者将类似的东西放在一起 这非常适合 iPhone 范式 后者意味着我会跳得更多 你怎么认为 标准的 Xcode MVC 文件
  • Chrome 中增加 5MB 存储限制

    我们有一个用 html5 编写的 POS 应用程序 我们使用 localStorage 来存储订单和其他信息 我遇到了 chrome 提供的 5MB 的限制 它导致应用程序崩溃 有没有简单的方法来增加这个限制 thanks 检查这个link
  • 何时断开连接以及何时结束 pg 客户端或池

    我的堆栈是node express 和pg 模块 我真的尝试通过文档和一些过时的教程来理解 我不知道何时以及如何断开和结束客户端 对于某些路线 我决定使用游泳池 这是我的代码 const pool new pg Pool user pool
  • Jaxb,类有两个同名属性

    使用 Jaxb jaxb impl 2 1 12 UI 尝试读取XML 文件 http www copypastecode com 75029 XML 文件中只有少数元素是有趣的 因此我想跳过大部分元素 我正在尝试读取的 XML