我正在使用来理解JAXB。
当编写器创建文档的根目录时,编写器开始如下所示:
//This statement means that class "Bookstore.java" is the root-element of our example
@XmlRootElement(namespace = "de.vogella.xml.jaxb.model")
public class Bookstore {
...
}
尽管我将手动生成我的类,而不是让Eclipse来生成,但是我将为我的jar文件(不是打包在里面,而是放在包含jar文件的文件
我有一个子类子,它来自于基类父级。我想在基类的属性上添加一个包装器。
Parent.java
package test;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Parent {
int a;
int b;
String name;
public Parent() {
}
public int getA() {
return a;
}
public void setA(int a) {
首先是一个小例子。类ReferencingEntity包含对抽象类AbstractEntity的引用。这个类有两个实现:
@XmlRootElement
public abstract class AbstractEntity {
@XmlID
private String id;
}
@XmlRootElement
public class EntityImpl1 extends AbstractEntity {
}
@XmlRootElement
public class EntityImpl2 extends AbstractEntity {
}
@XmlRo
我试图用JAXB编组一个简单的Java类,但遇到了错误。我正在寻找修复以下错误的建议,这些是错误:
javax.xml.bind.JAXBException
- with linked exception:
[java.io.FileNotFoundException: C:\file.xml (Access is denied)]
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown Source)
at JAXBExample.main(JAXBExample.java:23)
Caused by
我知道这似乎是个问题,但之前给出的任何答案似乎都没有帮助。
因此,问题是在尝试时使用FileNotFoundException:
File file = new File(ClassLoader.getSystemResource("xml/cheat_data.xml").toURI());
InputStream is = new BufferedInputStream(new FileInputStream(file));
或
InputStream is = new BufferedInputStream(new FileInputStream("xml/che
我得到了上述异常,寻找解决方案,任何帮助将非常感谢。在其他一些消息中发现了同样的问题,但它们对我不起作用。请看下面的代码。
javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: class com.mycompany.soma.ws.rest.v1.model.test.EmployeeConstruction nor any of its super class is known to this context.
javax.xml.bind.JAXBException
我有一个用@XmlAccessorType(XmlAccessType.NONE)注释为@XmlRootElement的类。我遇到的问题是,超类的方法正在被绑定,而我不希望它们被绑定,并且不能更新类。我希望有一个注释,我可以把它放在根元素类上,以防止这种情况发生。
示例:
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class Person extends NamedObject {
@XmlElement
public String getId() { ... }
}
我希望只有在Person上注
我已经看到了一些与此相关的讨论,但不能适用于以下情况。我正在尝试unmarshall an xml using jaxb。下面是我所有类的层次结构。
@XmlRootElement(name="entry")
class Entry extedns Base{
@XmlElement
private String id;
@XmlElement
private String name;
@XmlElementRef
@XmlMixed
private Begin begin;
@XmlElem
我一直在尝试使用JAXB解组以下XML内容。
<?xml version="1.0" encoding="utf-8"?>
<Root xmlns="http://wso2.org/2016/wso2as-web">
<Property Key="name">value</Property>
</Root>
在几篇文章中提到在这种情况下使用@XmlValue注释来检索文本内容,但到目前为止,由于以下问题,我失败了。
If a class has @XmlElem
我有如下的类层次结构:
@XmlRootElement
public abstract class Animal{}
@XmlRootElement
public class Dog extends Animal{}
@XmlRootElement
public class Cat extends Animal{}
@XmlRootElement
public class Lion extends Animal{}
还有一个类,它有一个名为animal的属性:
@XmlRootElement
public class Owner{
private Animal animal;
}
我
我已经将spring设置为使用: Jaxb2RootElementHttpMessageConverter作为消息转换器,将对象转换为xml。在我的rest服务中,当生成响应时,它不遵守我在模型类上提供的JAXB注释。
BaseResponse:
@XmlRootElement(name="response")
@XmlSeeAlso({AddMemberResponse.class,UpdateMemberResponse.class})
public abstract class BaseResponse {
private int status;
p
我有以下文件目录
WebContent/search.jsp
WebContent/xml/Car.hbm.xml
我正在创建实例化配置对象,如下所示:
Configuration cfg = new Configuration()
.addResource("xml/Car.hbm.xml");
但这导致了MappingException due to Car.hbm.xml file not found的出现。
指定映射文件路径的正确方法是什么?
我在中尝试了这种方法
但是我得到了一个
1 counts of IllegalAnnotationExceptions
XmlIDREF property is referencing a type "java.lang.String" that doesn't have an XmlID property.
this problem is related to the following location:
at private externalReferences.Department
externalReferences.E