1
我有这样的XML解组清单类型
<data-set>
<list-property name="columns">...</list-property>
<list-property name="resultSet">...</list-property>
<data-set>
需要解组此提出异议:
public class DataSet {
private Columns columns;
private ResultSet resultSet;
...
}
帮我实现,如果有可能。
更新 我试图这样做:
public class DataSet {
@XmlElement("list-property")
@XmlJavaTypeAdapter(DataSetListPropertyAdapter.class)
private Columns columns;
@XmlElement("list-property")
@XmlJavaTypeAdapter(DataSetListPropertyAdapter.class)
private ResultSet resultSet;
...
}
public class DataSetListPropertyAdapter extends XmlAdapter<ListProperty, ListProperty> {
@Override
public ListProperty unmarshal(ListProperty v) throws Exception {
ListProperty listProperty;
switch (v.getName()) {
case "columns":
listProperty = new Columns();
break;
case "resultSet":
listProperty = new ResultSet();
break;
default:
listProperty = new ListProperty();
}
listProperty.setStructure(v.getStructure());
return listProperty;
}
@Override
public ListProperty marshal(ListProperty v) throws Exception {
return v;
}
}
public class Columns extends ListProperty {
public Columns() {
name = "columns";
}
}
public class ListProperty extends NamedElement implements PropertyType{
@XmlElement(name = "structure")
private List<Structure> structure = new ArrayList<>();
}
@XmlTransient
public class NamedElement {
@XmlAttribute(name = "name", required = true)
protected String name;
}
当去解组解析的带注释的对象则只有第一个元素。另一个是空的。当我先评论然后第二个被解析。
THX您的答复。我认为这是我需要的。但我试图安装MOXY,但没有成功。我使用的WebSphere App容器已经有JAXB Provider。我如何使用它。我尝试将类加载器选项更改为PARENT_LAST,但之后发生错误com.ibm.ws.webcontainer.exception.WebAppNotLoadedException:加载webapp失败:javax.servlet.ServletContainerInitializer:Provider org.springframework.web.SpringServletContainerInitializer不是子类型。 WebSphere 8.5.5.11 –
您是否按照以下说明操作:http://www.eclipse.org/eclipselink/documentation/2.5/solutions/websphere.htm? –
我认为这应该是另一个问题。谢谢 –