我使用Eclipselink 2.3.2作为我的JAXB(JSR-222)提供程序.我创建了一个通用列表,其中包含一个项目列表和一组分页链接.
import java.util.List;
import javax.xml.bind.annotation.*;
@XmlRootElement(name = "listdata")
public class ListEntity<T> {
@XmlElementRef
public List<T> data;
@XmlElementRef
public PaginationLinks links;
public ListEntity(List<T> data) {
this.data = data;
}
public ListEntity() {
}
}
Run Code Online (Sandbox Code Playgroud)
我的实际实体
@XmlRootElement(name="authorization")
public class AuthorizationDTO {
@XmlElement
public String referenceNumber;
}
Run Code Online (Sandbox Code Playgroud)
因此,在创建列表后,当我尝试编组它时,我收到以下错误.适用于List数据的@XmlElement可以正常工作,但显然无法使用,因为它会创建Object表示
Caused by: Exception [EclipseLink-50006] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Invalid XmlElementRef on property data on class com.ofss.fc.botg.infra.model.ListEntity. Referenced Element not declared.
Run Code Online (Sandbox Code Playgroud) 所以继承我的问题.我有两个类... SingularEntity和ListEntity.顾名思义,SingularEntity表示一个实体,ListEntity表示一个奇异实体列表......该列表显然具有比SingularEntity本身更常见的属性.所以我有一个AuthorizationEntity扩展了SingularEntity类
public class SingularEntity{
}
public class AuthorizationEntity extends SingularEntity{
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个ListEntity,它代表任何SingularEntities的List
public class ListEntity{
public List<? extends SingularEntity> data;
public ListEntity(List<? extends SingularEntity> data){
this.data = data;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我想使用反射来总是填充列表....我总是在results.add方法中遇到错误.说方法List.add(CAP#1)不适用.任何帮助都很高兴
public List<? extends SingularEntity> build() {
List<? extends SingularEntity> results = new ArrayList<SingularEntity>();
try {
Constructor javaBeanClassConstructor =
(Constructor) DTOClass.getDeclaredConstructors()[0];
Class<?>[] constructorParameterTypes =
javaBeanClassConstructor.getParameterTypes();
for (Object[] columns : lstInput) {
Object[] constructorArgs = new Object[constructorParameterTypes.length];
for (int j = 0; j < columns.length; j++) {
Object columnValue = …Run Code Online (Sandbox Code Playgroud)