急!!CXF返回类型为List<Map>的问题 10
#service:@WebMethod@XmlJavaTypeAdapter(MapInListAdapter.class)publicList<Map<String,S...
#service:
@WebMethod
@XmlJavaTypeAdapter(MapInListAdapter.class)
public List<Map<String,String>> getMember();
#adapter:
public class MapInListAdapter extends XmlAdapter<MapInListConvertor,List<Map>>{
@Override
public MapInListConvertor marshal(List<Map> list) throws Exception {
System.out.println("marshaling..");
MapInListConvertor convertor = new MapInListConvertor();
for(Map<Object,Object> map : list){
MapConvertor mc = new MapConvertor();
for(Entry<Object,Object> entry : map.entrySet()){
mc.addEntry(new MapEntry(entry));
}
convertor.addMapConvertor(mc);
}
return convertor;
}
@Override
public List<Map> unmarshal(MapInListConvertor convertor) throws Exception {
System.out.println("unmarshaling..");
List<Map> list = new ArrayList();
for(MapConvertor mc : convertor.getMapConvertorList()){
Map map = new HashMap();
for(MapEntry entry : mc.getEntries()){
map.put(entry.getKey(), entry.getValue());
}
list.add(map);
}
return list;
}
}
convertor:
@XmlType(name = "MapConvertor")
@XmlAccessorType(XmlAccessType.FIELD)
public class MapConvertor {
private List<MapEntry> entries = new ArrayList<MapEntry>();
public void addEntry(MapEntry entry){
entries.add(entry);
}
public List<MapEntry> getEntries() {
return entries;
}
public void setEntries(List<MapEntry> entries) {
this.entries = entries;
}
public static class MapEntry {
private Object key;
private Object value;
public MapEntry(){}
public MapEntry(Map.Entry<Object,Object> entry){
this.key = entry.getKey();
this.value = entry.getValue();
}
public MapEntry(Object key , Object value){
this.key = key;
this.value = value;
}
public Object getKey() {
return key;
}
public void setKey(Object key) {
this.key = key;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}
}
客户端运行的时候确报:
javax.xml.ws.soap.SOAPFaultException: java.util.ArrayList cannot be cast to java.util.Map
小弟经验尚浅,希望各位大哥们给点指示 展开
@WebMethod
@XmlJavaTypeAdapter(MapInListAdapter.class)
public List<Map<String,String>> getMember();
#adapter:
public class MapInListAdapter extends XmlAdapter<MapInListConvertor,List<Map>>{
@Override
public MapInListConvertor marshal(List<Map> list) throws Exception {
System.out.println("marshaling..");
MapInListConvertor convertor = new MapInListConvertor();
for(Map<Object,Object> map : list){
MapConvertor mc = new MapConvertor();
for(Entry<Object,Object> entry : map.entrySet()){
mc.addEntry(new MapEntry(entry));
}
convertor.addMapConvertor(mc);
}
return convertor;
}
@Override
public List<Map> unmarshal(MapInListConvertor convertor) throws Exception {
System.out.println("unmarshaling..");
List<Map> list = new ArrayList();
for(MapConvertor mc : convertor.getMapConvertorList()){
Map map = new HashMap();
for(MapEntry entry : mc.getEntries()){
map.put(entry.getKey(), entry.getValue());
}
list.add(map);
}
return list;
}
}
convertor:
@XmlType(name = "MapConvertor")
@XmlAccessorType(XmlAccessType.FIELD)
public class MapConvertor {
private List<MapEntry> entries = new ArrayList<MapEntry>();
public void addEntry(MapEntry entry){
entries.add(entry);
}
public List<MapEntry> getEntries() {
return entries;
}
public void setEntries(List<MapEntry> entries) {
this.entries = entries;
}
public static class MapEntry {
private Object key;
private Object value;
public MapEntry(){}
public MapEntry(Map.Entry<Object,Object> entry){
this.key = entry.getKey();
this.value = entry.getValue();
}
public MapEntry(Object key , Object value){
this.key = key;
this.value = value;
}
public Object getKey() {
return key;
}
public void setKey(Object key) {
this.key = key;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}
}
客户端运行的时候确报:
javax.xml.ws.soap.SOAPFaultException: java.util.ArrayList cannot be cast to java.util.Map
小弟经验尚浅,希望各位大哥们给点指示 展开
8个回答
展开全部
遇到同样的问题!一年了,竟没个人出来指点。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
3年了,还是没人解决吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2018-01-23
展开全部
哎~~7年之痒啊,结案了~还是没有答案啊。WebService是不是该淘汰了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
五年半了,居然还没有人来解决,哎!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询