包含集合作为值的地图有些棘手。您需要一个适配器和类来以JAXB可以处理的方式表示映射条目。
@XmlAccessorType(XmlAccessType.FIELD) public class ListOfEntry { @XmlElement private List<Entry> list = new ArrayList<>(); public List<Entry> getList(){ return list; } } @XmlAccessorType(XmlAccessType.FIELD) public class Entry { @XmlElement private String key; @XmlElement private List<Parameter> list = new ArrayList<>(); public String getKey(){ return key; } public void setKey( String value ){ key = value; } public List<Parameter> getList(){ return list; } }
@H_502_5@适配器来回进行转换:
public class Adapter extends XmlAdapter<ListOfEntry, Map<String, List<Parameter>>> { @Override public Map<String, List<Parameter>> unmarshal(ListOfEntry loe) throws Exception { Map<String, List<Parameter>> map = new HashMap<>(); for(Entry entry : loe.getList() ) { map.put(entry.getKey(), entry.getList() ); } return map; } @Override public ListOfEntry marshal(Map<String, List<Parameter>> map) throws Exception { ListOfEntry loe = new ListOfEntry(); for(Map.Entry<String, List<Parameter>> mapEntry : map.entrySet()) { Entry entry = new Entry(); entry.setKey( mapEntry.getKey() ); entry.getList().addAll( mapEntry.getValue() ); loe.getList().add(entry); } return loe; } }
@H_502_5@并且必须在“地图”字段中添加注释:
@XmlElement @XmlJavaTypeAdapter(Adapter.class) private Map<String, List<Parameter>> parameterMap = new HashMap<>();
@H_502_5@解决方法
我在代码中遇到问题。
@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @Entity @NamedQueries({ @NamedQuery(name = Parameter.FIND_ALL,query = "SELECT pm FROM Parameter pm") }) public class Parameter implements Serializable { public static final String FIND_ALL = "Parameter.findAll"; @XmlTransient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @XmlAttribute private String type; private String name; // Setters and Getters } @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ParameterMap { private Map<String,List<Parameter>> parameterMap = new HashMap<String,List<Parameter>>(); @XmlElement public Map<String,List<Parameter>> getParameterMap() { return parameterMap; } public void setParmeterMap(Map<String,List<Parameter>> parameterMap) { this.parameterMap = parameterMap; } } @Path("/parameter") public class ParameterRESTResource { @Inject private ParameterService paramService; @GET @Path("/") @Produces({ MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML }) public List<Parameter> getAllParameters() throws JAXBException { ParameterMap parameterMap = formatParameters(paramService.getAllParameters()); JAXBContext jaxbContext = JAXBContext.newInstance(ParameterMap.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true); jaxbMarshaller.marshal(parameterMap,System.out); jaxbMarshaller.marshal(parameterMap,new File("c:/temp/employees.xml")); return paramService.getAllParameters(); } public ParameterMap formatParameters(List<Parameter> parameters) { HashMap<String,List<Parameter>>(); ParameterMap paramMap = new ParameterMap(); Parameter param = null; List<Parameter> list = null; for (int i = 0; i < parameters.size(); i++) { param = new Parameter(); param = parameters.get(i); if (param.getType() != "text") { list = new ArrayList<Parameter>(); if (parameterMap.containsKey(param.getName())) { list = parameterMap.get(param.getName()); list.add(param); } else { list = new ArrayList<Parameter>(); list.add(param); } } else { list = new ArrayList<Parameter>(); list.add(param); } parameterMap.put(param.getName(),list); } paramMap.setParmeterMap(parameterMap); return paramMap; } }
当我在本地(http:// localhost:8080 / home / rest / parameter
/)上运行应用程序时,出现以下错误。我的主要要求是Map<String,List<Parameters>>
在xml上的UI上显示所有信息。org.jboss.resteasy.spi.UnhandledException:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions的1个计数java.util.List是一个接口,JAXB无法处理接口。此问题与以下位置有关:在java.util.List处在私有java.util.Map处nl.paston.insurance.product.model.ParameterMap.parameterMap在nl.paston.insurance.product.model.ParameterMap
org.jboss
.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)org.jboss.resteasy.core.SynchronousDispatcher。我希望我已经提供了所有需要的信息。在这个专家小组中,请大家在这个问题上帮助我。任何小的帮助对我来说都是最大的帮助。感谢您的帮助。
public class Adapter extends XmlAdapter<ListOfEntry, Map<String, List<Parameter>>> { @Override public Map<String, List<Parameter>> unmarshal(ListOfEntry loe) throws Exception { Map<String, List<Parameter>> map = new HashMap<>(); for(Entry entry : loe.getList() ) { map.put(entry.getKey(), entry.getList() ); } return map; } @Override public ListOfEntry marshal(Map<String, List<Parameter>> map) throws Exception { ListOfEntry loe = new ListOfEntry(); for(Map.Entry<String, List<Parameter>> mapEntry : map.entrySet()) { Entry entry = new Entry(); entry.setKey( mapEntry.getKey() ); entry.getList().addAll( mapEntry.getValue() ); loe.getList().add(entry); } return loe; } }
@H_502_5@并且必须在“地图”字段中添加注释:
@XmlElement @XmlJavaTypeAdapter(Adapter.class) private Map<String, List<Parameter>> parameterMap = new HashMap<>();
@H_502_5@解决方法
我在代码中遇到问题。
@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @Entity @NamedQueries({ @NamedQuery(name = Parameter.FIND_ALL,query = "SELECT pm FROM Parameter pm") }) public class Parameter implements Serializable { public static final String FIND_ALL = "Parameter.findAll"; @XmlTransient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @XmlAttribute private String type; private String name; // Setters and Getters } @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ParameterMap { private Map<String,List<Parameter>> parameterMap = new HashMap<String,List<Parameter>>(); @XmlElement public Map<String,List<Parameter>> getParameterMap() { return parameterMap; } public void setParmeterMap(Map<String,List<Parameter>> parameterMap) { this.parameterMap = parameterMap; } } @Path("/parameter") public class ParameterRESTResource { @Inject private ParameterService paramService; @GET @Path("/") @Produces({ MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML }) public List<Parameter> getAllParameters() throws JAXBException { ParameterMap parameterMap = formatParameters(paramService.getAllParameters()); JAXBContext jaxbContext = JAXBContext.newInstance(ParameterMap.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true); jaxbMarshaller.marshal(parameterMap,System.out); jaxbMarshaller.marshal(parameterMap,new File("c:/temp/employees.xml")); return paramService.getAllParameters(); } public ParameterMap formatParameters(List<Parameter> parameters) { HashMap<String,List<Parameter>>(); ParameterMap paramMap = new ParameterMap(); Parameter param = null; List<Parameter> list = null; for (int i = 0; i < parameters.size(); i++) { param = new Parameter(); param = parameters.get(i); if (param.getType() != "text") { list = new ArrayList<Parameter>(); if (parameterMap.containsKey(param.getName())) { list = parameterMap.get(param.getName()); list.add(param); } else { list = new ArrayList<Parameter>(); list.add(param); } } else { list = new ArrayList<Parameter>(); list.add(param); } parameterMap.put(param.getName(),list); } paramMap.setParmeterMap(parameterMap); return paramMap; } }
当我在本地(http:// localhost:8080 / home / rest / parameter
/)上运行应用程序时,出现以下错误。我的主要要求是Map<String,List<Parameters>>
在xml上的UI上显示所有信息。org.jboss.resteasy.spi.UnhandledException:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions的1个计数java.util.List是一个接口,JAXB无法处理接口。此问题与以下位置有关:在java.util.List处在私有java.util.Map处nl.paston.insurance.product.model.ParameterMap.parameterMap在nl.paston.insurance.product.model.ParameterMap
org.jboss
.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)org.jboss.resteasy.core.SynchronousDispatcher。我希望我已经提供了所有需要的信息。在这个专家小组中,请大家在这个问题上帮助我。任何小的帮助对我来说都是最大的帮助。感谢您的帮助。
@XmlElement @XmlJavaTypeAdapter(Adapter.class) private Map<String, List<Parameter>> parameterMap = new HashMap<>();
@H_502_5@解决方法
我在代码中遇到问题。
@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @Entity @NamedQueries({ @NamedQuery(name = Parameter.FIND_ALL,query = "SELECT pm FROM Parameter pm") }) public class Parameter implements Serializable { public static final String FIND_ALL = "Parameter.findAll"; @XmlTransient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @XmlAttribute private String type; private String name; // Setters and Getters } @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ParameterMap { private Map<String,List<Parameter>> parameterMap = new HashMap<String,List<Parameter>>(); @XmlElement public Map<String,List<Parameter>> getParameterMap() { return parameterMap; } public void setParmeterMap(Map<String,List<Parameter>> parameterMap) { this.parameterMap = parameterMap; } } @Path("/parameter") public class ParameterRESTResource { @Inject private ParameterService paramService; @GET @Path("/") @Produces({ MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML }) public List<Parameter> getAllParameters() throws JAXBException { ParameterMap parameterMap = formatParameters(paramService.getAllParameters()); JAXBContext jaxbContext = JAXBContext.newInstance(ParameterMap.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true); jaxbMarshaller.marshal(parameterMap,System.out); jaxbMarshaller.marshal(parameterMap,new File("c:/temp/employees.xml")); return paramService.getAllParameters(); } public ParameterMap formatParameters(List<Parameter> parameters) { HashMap<String,List<Parameter>>(); ParameterMap paramMap = new ParameterMap(); Parameter param = null; List<Parameter> list = null; for (int i = 0; i < parameters.size(); i++) { param = new Parameter(); param = parameters.get(i); if (param.getType() != "text") { list = new ArrayList<Parameter>(); if (parameterMap.containsKey(param.getName())) { list = parameterMap.get(param.getName()); list.add(param); } else { list = new ArrayList<Parameter>(); list.add(param); } } else { list = new ArrayList<Parameter>(); list.add(param); } parameterMap.put(param.getName(),list); } paramMap.setParmeterMap(parameterMap); return paramMap; } }
当我在本地(http:// localhost:8080 / home / rest / parameter
/)上运行应用程序时,出现以下错误。我的主要要求是Map<String,List<Parameters>>
在xml上的UI上显示所有信息。org.jboss.resteasy.spi.UnhandledException:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions的1个计数java.util.List是一个接口,JAXB无法处理接口。此问题与以下位置有关:在java.util.List处在私有java.util.Map处nl.paston.insurance.product.model.ParameterMap.parameterMap在nl.paston.insurance.product.model.ParameterMap
org.jboss
.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)org.jboss.resteasy.core.SynchronousDispatcher。我希望我已经提供了所有需要的信息。在这个专家小组中,请大家在这个问题上帮助我。任何小的帮助对我来说都是最大的帮助。感谢您的帮助。
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@NamedQueries({
@NamedQuery(name = Parameter.FIND_ALL,query = "SELECT pm FROM Parameter pm")
})
public class Parameter implements Serializable {
public static final String FIND_ALL = "Parameter.findAll";
@XmlTransient
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long id;
@XmlAttribute
private String type;
private String name;
// Setters and Getters
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ParameterMap {
private Map<String,List<Parameter>> parameterMap = new HashMap<String,List<Parameter>>();
@XmlElement
public Map<String,List<Parameter>> getParameterMap() {
return parameterMap;
}
public void setParmeterMap(Map<String,List<Parameter>> parameterMap) {
this.parameterMap = parameterMap;
}
}
@Path("/parameter")
public class ParameterRESTResource {
@Inject
private ParameterService paramService;
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML })
public List<Parameter> getAllParameters() throws JAXBException {
ParameterMap parameterMap = formatParameters(paramService.getAllParameters());
JAXBContext jaxbContext = JAXBContext.newInstance(ParameterMap.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
jaxbMarshaller.marshal(parameterMap,System.out);
jaxbMarshaller.marshal(parameterMap,new File("c:/temp/employees.xml"));
return paramService.getAllParameters();
}
public ParameterMap formatParameters(List<Parameter> parameters) {
HashMap<String,List<Parameter>>();
ParameterMap paramMap = new ParameterMap();
Parameter param = null;
List<Parameter> list = null;
for (int i = 0; i < parameters.size(); i++) {
param = new Parameter();
param = parameters.get(i);
if (param.getType() != "text") {
list = new ArrayList<Parameter>();
if (parameterMap.containsKey(param.getName())) {
list = parameterMap.get(param.getName());
list.add(param);
}
else {
list = new ArrayList<Parameter>();
list.add(param);
}
}
else {
list = new ArrayList<Parameter>();
list.add(param);
}
parameterMap.put(param.getName(),list);
}
paramMap.setParmeterMap(parameterMap);
return paramMap;
}
}
适配器来回进行转换:
并且必须在“地图”字段中添加注释:
我在代码中遇到问题。
当我在本地(http:// localhost:8080 / home / rest / parameter
/)上运行应用程序时,出现以下错误。我的主要要求是Map<String,List<Parameters>>
在xml上的UI上显示所有信息。
org.jboss.resteasy.spi.UnhandledException:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions的1个计数java.util.List是一个接口,JAXB无法处理接口。此问题与以下位置有关:在java.util.List处在私有java.util.Map处nl.paston.insurance.product.model.ParameterMap.parameterMap在nl.paston.insurance.product.model.ParameterMap
org.jboss
.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)org.jboss.resteasy.core.SynchronousDispatcher。
我希望我已经提供了所有需要的信息。在这个专家小组中,请大家在这个问题上帮助我。任何小的帮助对我来说都是最大的帮助。感谢您的帮助。
适配器来回进行转换:
public class Adapter extends XmlAdapter<ListOfEntry, Map<String, List<Parameter>>> { @Override public Map<String, List<Parameter>> unmarshal(ListOfEntry loe) throws Exception { Map<String, List<Parameter>> map = new HashMap<>(); for(Entry entry : loe.getList() ) { map.put(entry.getKey(), entry.getList() ); } return map; } @Override public ListOfEntry marshal(Map<String, List<Parameter>> map) throws Exception { ListOfEntry loe = new ListOfEntry(); for(Map.Entry<String, List<Parameter>> mapEntry : map.entrySet()) { Entry entry = new Entry(); entry.setKey( mapEntry.getKey() ); entry.getList().addAll( mapEntry.getValue() ); loe.getList().add(entry); } return loe; } }
@H_502_5@并且必须在“地图”字段中添加注释:
@XmlElement @XmlJavaTypeAdapter(Adapter.class) private Map<String, List<Parameter>> parameterMap = new HashMap<>();
@H_502_5@解决方法
我在代码中遇到问题。
@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @Entity @NamedQueries({ @NamedQuery(name = Parameter.FIND_ALL,query = "SELECT pm FROM Parameter pm") }) public class Parameter implements Serializable { public static final String FIND_ALL = "Parameter.findAll"; @XmlTransient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @XmlAttribute private String type; private String name; // Setters and Getters } @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ParameterMap { private Map<String,List<Parameter>> parameterMap = new HashMap<String,List<Parameter>>(); @XmlElement public Map<String,List<Parameter>> getParameterMap() { return parameterMap; } public void setParmeterMap(Map<String,List<Parameter>> parameterMap) { this.parameterMap = parameterMap; } } @Path("/parameter") public class ParameterRESTResource { @Inject private ParameterService paramService; @GET @Path("/") @Produces({ MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML }) public List<Parameter> getAllParameters() throws JAXBException { ParameterMap parameterMap = formatParameters(paramService.getAllParameters()); JAXBContext jaxbContext = JAXBContext.newInstance(ParameterMap.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true); jaxbMarshaller.marshal(parameterMap,System.out); jaxbMarshaller.marshal(parameterMap,new File("c:/temp/employees.xml")); return paramService.getAllParameters(); } public ParameterMap formatParameters(List<Parameter> parameters) { HashMap<String,List<Parameter>>(); ParameterMap paramMap = new ParameterMap(); Parameter param = null; List<Parameter> list = null; for (int i = 0; i < parameters.size(); i++) { param = new Parameter(); param = parameters.get(i); if (param.getType() != "text") { list = new ArrayList<Parameter>(); if (parameterMap.containsKey(param.getName())) { list = parameterMap.get(param.getName()); list.add(param); } else { list = new ArrayList<Parameter>(); list.add(param); } } else { list = new ArrayList<Parameter>(); list.add(param); } parameterMap.put(param.getName(),list); } paramMap.setParmeterMap(parameterMap); return paramMap; } }
当我在本地(http:// localhost:8080 / home / rest / parameter
/)上运行应用程序时,出现以下错误。我的主要要求是Map<String,List<Parameters>>
在xml上的UI上显示所有信息。org.jboss.resteasy.spi.UnhandledException:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions的1个计数java.util.List是一个接口,JAXB无法处理接口。此问题与以下位置有关:在java.util.List处在私有java.util.Map处nl.paston.insurance.product.model.ParameterMap.parameterMap在nl.paston.insurance.product.model.ParameterMap
org.jboss
.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)org.jboss.resteasy.core.SynchronousDispatcher。我希望我已经提供了所有需要的信息。在这个专家小组中,请大家在这个问题上帮助我。任何小的帮助对我来说都是最大的帮助。感谢您的帮助。
@XmlElement @XmlJavaTypeAdapter(Adapter.class) private Map<String, List<Parameter>> parameterMap = new HashMap<>();
@H_502_5@解决方法
我在代码中遇到问题。
@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @Entity @NamedQueries({ @NamedQuery(name = Parameter.FIND_ALL,query = "SELECT pm FROM Parameter pm") }) public class Parameter implements Serializable { public static final String FIND_ALL = "Parameter.findAll"; @XmlTransient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @XmlAttribute private String type; private String name; // Setters and Getters } @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ParameterMap { private Map<String,List<Parameter>> parameterMap = new HashMap<String,List<Parameter>>(); @XmlElement public Map<String,List<Parameter>> getParameterMap() { return parameterMap; } public void setParmeterMap(Map<String,List<Parameter>> parameterMap) { this.parameterMap = parameterMap; } } @Path("/parameter") public class ParameterRESTResource { @Inject private ParameterService paramService; @GET @Path("/") @Produces({ MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML }) public List<Parameter> getAllParameters() throws JAXBException { ParameterMap parameterMap = formatParameters(paramService.getAllParameters()); JAXBContext jaxbContext = JAXBContext.newInstance(ParameterMap.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true); jaxbMarshaller.marshal(parameterMap,System.out); jaxbMarshaller.marshal(parameterMap,new File("c:/temp/employees.xml")); return paramService.getAllParameters(); } public ParameterMap formatParameters(List<Parameter> parameters) { HashMap<String,List<Parameter>>(); ParameterMap paramMap = new ParameterMap(); Parameter param = null; List<Parameter> list = null; for (int i = 0; i < parameters.size(); i++) { param = new Parameter(); param = parameters.get(i); if (param.getType() != "text") { list = new ArrayList<Parameter>(); if (parameterMap.containsKey(param.getName())) { list = parameterMap.get(param.getName()); list.add(param); } else { list = new ArrayList<Parameter>(); list.add(param); } } else { list = new ArrayList<Parameter>(); list.add(param); } parameterMap.put(param.getName(),list); } paramMap.setParmeterMap(parameterMap); return paramMap; } }
当我在本地(http:// localhost:8080 / home / rest / parameter
/)上运行应用程序时,出现以下错误。我的主要要求是Map<String,List<Parameters>>
在xml上的UI上显示所有信息。org.jboss.resteasy.spi.UnhandledException:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions的1个计数java.util.List是一个接口,JAXB无法处理接口。此问题与以下位置有关:在java.util.List处在私有java.util.Map处nl.paston.insurance.product.model.ParameterMap.parameterMap在nl.paston.insurance.product.model.ParameterMap
org.jboss
.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)org.jboss.resteasy.core.SynchronousDispatcher。我希望我已经提供了所有需要的信息。在这个专家小组中,请大家在这个问题上帮助我。任何小的帮助对我来说都是最大的帮助。感谢您的帮助。
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@NamedQueries({
@NamedQuery(name = Parameter.FIND_ALL,query = "SELECT pm FROM Parameter pm")
})
public class Parameter implements Serializable {
public static final String FIND_ALL = "Parameter.findAll";
@XmlTransient
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long id;
@XmlAttribute
private String type;
private String name;
// Setters and Getters
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ParameterMap {
private Map<String,List<Parameter>> parameterMap = new HashMap<String,List<Parameter>>();
@XmlElement
public Map<String,List<Parameter>> getParameterMap() {
return parameterMap;
}
public void setParmeterMap(Map<String,List<Parameter>> parameterMap) {
this.parameterMap = parameterMap;
}
}
@Path("/parameter")
public class ParameterRESTResource {
@Inject
private ParameterService paramService;
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML })
public List<Parameter> getAllParameters() throws JAXBException {
ParameterMap parameterMap = formatParameters(paramService.getAllParameters());
JAXBContext jaxbContext = JAXBContext.newInstance(ParameterMap.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
jaxbMarshaller.marshal(parameterMap,System.out);
jaxbMarshaller.marshal(parameterMap,new File("c:/temp/employees.xml"));
return paramService.getAllParameters();
}
public ParameterMap formatParameters(List<Parameter> parameters) {
HashMap<String,List<Parameter>>();
ParameterMap paramMap = new ParameterMap();
Parameter param = null;
List<Parameter> list = null;
for (int i = 0; i < parameters.size(); i++) {
param = new Parameter();
param = parameters.get(i);
if (param.getType() != "text") {
list = new ArrayList<Parameter>();
if (parameterMap.containsKey(param.getName())) {
list = parameterMap.get(param.getName());
list.add(param);
}
else {
list = new ArrayList<Parameter>();
list.add(param);
}
}
else {
list = new ArrayList<Parameter>();
list.add(param);
}
parameterMap.put(param.getName(),list);
}
paramMap.setParmeterMap(parameterMap);
return paramMap;
}
}
并且必须在“地图”字段中添加注释:
我在代码中遇到问题。
当我在本地(http:// localhost:8080 / home / rest / parameter
/)上运行应用程序时,出现以下错误。我的主要要求是Map<String,List<Parameters>>
在xml上的UI上显示所有信息。
org.jboss.resteasy.spi.UnhandledException:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions的1个计数java.util.List是一个接口,JAXB无法处理接口。此问题与以下位置有关:在java.util.List处在私有java.util.Map处nl.paston.insurance.product.model.ParameterMap.parameterMap在nl.paston.insurance.product.model.ParameterMap
org.jboss
.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)org.jboss.resteasy.core.SynchronousDispatcher。
我希望我已经提供了所有需要的信息。在这个专家小组中,请大家在这个问题上帮助我。任何小的帮助对我来说都是最大的帮助。感谢您的帮助。
并且必须在“地图”字段中添加注释:
@XmlElement @XmlJavaTypeAdapter(Adapter.class) private Map<String, List<Parameter>> parameterMap = new HashMap<>();
@H_502_5@解决方法
我在代码中遇到问题。
@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @Entity @NamedQueries({ @NamedQuery(name = Parameter.FIND_ALL,query = "SELECT pm FROM Parameter pm") }) public class Parameter implements Serializable { public static final String FIND_ALL = "Parameter.findAll"; @XmlTransient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @XmlAttribute private String type; private String name; // Setters and Getters } @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ParameterMap { private Map<String,List<Parameter>> parameterMap = new HashMap<String,List<Parameter>>(); @XmlElement public Map<String,List<Parameter>> getParameterMap() { return parameterMap; } public void setParmeterMap(Map<String,List<Parameter>> parameterMap) { this.parameterMap = parameterMap; } } @Path("/parameter") public class ParameterRESTResource { @Inject private ParameterService paramService; @GET @Path("/") @Produces({ MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML }) public List<Parameter> getAllParameters() throws JAXBException { ParameterMap parameterMap = formatParameters(paramService.getAllParameters()); JAXBContext jaxbContext = JAXBContext.newInstance(ParameterMap.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true); jaxbMarshaller.marshal(parameterMap,System.out); jaxbMarshaller.marshal(parameterMap,new File("c:/temp/employees.xml")); return paramService.getAllParameters(); } public ParameterMap formatParameters(List<Parameter> parameters) { HashMap<String,List<Parameter>>(); ParameterMap paramMap = new ParameterMap(); Parameter param = null; List<Parameter> list = null; for (int i = 0; i < parameters.size(); i++) { param = new Parameter(); param = parameters.get(i); if (param.getType() != "text") { list = new ArrayList<Parameter>(); if (parameterMap.containsKey(param.getName())) { list = parameterMap.get(param.getName()); list.add(param); } else { list = new ArrayList<Parameter>(); list.add(param); } } else { list = new ArrayList<Parameter>(); list.add(param); } parameterMap.put(param.getName(),list); } paramMap.setParmeterMap(parameterMap); return paramMap; } }
当我在本地(http:// localhost:8080 / home / rest / parameter
/)上运行应用程序时,出现以下错误。我的主要要求是Map<String,List<Parameters>>
在xml上的UI上显示所有信息。org.jboss.resteasy.spi.UnhandledException:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions的1个计数java.util.List是一个接口,JAXB无法处理接口。此问题与以下位置有关:在java.util.List处在私有java.util.Map处nl.paston.insurance.product.model.ParameterMap.parameterMap在nl.paston.insurance.product.model.ParameterMap
org.jboss
.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)org.jboss.resteasy.core.SynchronousDispatcher。我希望我已经提供了所有需要的信息。在这个专家小组中,请大家在这个问题上帮助我。任何小的帮助对我来说都是最大的帮助。感谢您的帮助。
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@NamedQueries({
@NamedQuery(name = Parameter.FIND_ALL,query = "SELECT pm FROM Parameter pm")
})
public class Parameter implements Serializable {
public static final String FIND_ALL = "Parameter.findAll";
@XmlTransient
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long id;
@XmlAttribute
private String type;
private String name;
// Setters and Getters
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ParameterMap {
private Map<String,List<Parameter>> parameterMap = new HashMap<String,List<Parameter>>();
@XmlElement
public Map<String,List<Parameter>> getParameterMap() {
return parameterMap;
}
public void setParmeterMap(Map<String,List<Parameter>> parameterMap) {
this.parameterMap = parameterMap;
}
}
@Path("/parameter")
public class ParameterRESTResource {
@Inject
private ParameterService paramService;
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML })
public List<Parameter> getAllParameters() throws JAXBException {
ParameterMap parameterMap = formatParameters(paramService.getAllParameters());
JAXBContext jaxbContext = JAXBContext.newInstance(ParameterMap.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
jaxbMarshaller.marshal(parameterMap,System.out);
jaxbMarshaller.marshal(parameterMap,new File("c:/temp/employees.xml"));
return paramService.getAllParameters();
}
public ParameterMap formatParameters(List<Parameter> parameters) {
HashMap<String,List<Parameter>>();
ParameterMap paramMap = new ParameterMap();
Parameter param = null;
List<Parameter> list = null;
for (int i = 0; i < parameters.size(); i++) {
param = new Parameter();
param = parameters.get(i);
if (param.getType() != "text") {
list = new ArrayList<Parameter>();
if (parameterMap.containsKey(param.getName())) {
list = parameterMap.get(param.getName());
list.add(param);
}
else {
list = new ArrayList<Parameter>();
list.add(param);
}
}
else {
list = new ArrayList<Parameter>();
list.add(param);
}
parameterMap.put(param.getName(),list);
}
paramMap.setParmeterMap(parameterMap);
return paramMap;
}
}
我在代码中遇到问题。
当我在本地(http:// localhost:8080 / home / rest / parameter
/)上运行应用程序时,出现以下错误。我的主要要求是Map<String,List<Parameters>>
在xml上的UI上显示所有信息。
org.jboss.resteasy.spi.UnhandledException:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions的1个计数java.util.List是一个接口,JAXB无法处理接口。此问题与以下位置有关:在java.util.List处在私有java.util.Map处nl.paston.insurance.product.model.ParameterMap.parameterMap在nl.paston.insurance.product.model.ParameterMap
org.jboss
.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)org.jboss.resteasy.core.SynchronousDispatcher。
我希望我已经提供了所有需要的信息。在这个专家小组中,请大家在这个问题上帮助我。任何小的帮助对我来说都是最大的帮助。感谢您的帮助。