Tag: oxm

Jibx – 如何使用值和属性解组/编组标记?

12 72 对不起伙计们,我本来不想偷懒。 好的问题是:我的xml结构带有上面的xml块,其中一些标签在标记符号中具有值和属性(MyTag的值为12且具有属性名称)。 使用Jibx如何为这种情况创建绑定模式。 显然,对于只有值的xml标签或没有标签值的属性是正常的,但当你同时拥有它们时我不知道该怎么做。 谢谢。

jaxb:枚举列表中的奇怪类强制转换exception

我正在使用jaxb从xsd文件生成java类。 xsd包含元素的定义,其内容是在与枚举相同的xsd定义的常量列表。 当使用来自oracle的jdk1.7 ( v2.2.4-2 )的JAXB参考实现生成类时,可以迭代枚举列表并为它们分配相同类型的变量。 但是,当使用oracle的jdk1.8 (构建1.8.0_45-b15 – 发布日期的最新版本)JAXB参考实现( v2.2.8-b130911.1802 )生成类时,不再可能分配列表的元素到枚举类型的变量。 任何使用增强型for循环分配或迭代的尝试都以ClassCastException结束 java.lang.ClassCastException: java.lang.String cannot be cast to so.jaxb.enums.generated.GConstNameType at so.jaxb.enums.domain.TestReader.readTest(TestReader.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) […]

将XML映射到Java中的对象

假设我有一个名为Test的类,就像这样 public class Test { private String testId; private String description; private String department; public Test() {} public Test(String id,String des,String dpt) { this.testId = id; this.department = dpt; this.description = des; } public String getTestId() { return testId; } public void setTestId(String testId) { this.testId = testId; } public String getDescription() { return description; […]

JAXB HashMap无法映射

我想将POJO类中的HashMap转换为XML。 我尝试使用XmlAdapter但它只导致HashMap的键和值对是XML Elements的属性。 我需要将Key作为Element本身,并将HashMap的值作为元素的值。 例如,我需要以下XML: 555 123.45 12345 card Q 123.45 2333 cash Q 我创建了以下类:MyMapType包含MyMapEntryType类的列表,该类包含两个字段,即Key和Value。 如何将Key元素更改为@XmlElement并将值字段分配给Key字段? 这是我的源文件。 MyMapType.java import java.util.ArrayList; import java.util.List; public class MyMapType { private List entry = new ArrayList(); public List getEntry() { return entry; } public void setEntry(List entry) { this.entry = entry; } } MyMapEntryType.java import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import […]