您的位置:首页 > 编程语言 > Java开发

7.当形参,返回值类型不是JavaBean式的复合类,Map时,CXF无法处理:转换器1

2012-07-23 10:48 686 查看
package org.fkjava.cfx.util;

import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import org.fkjava.cfx.domain.Cat;
import org.fkjava.cfx.util.StringCat.Entry;

/**
* 转换器,该转换起完成StringCat和Map<String, Cat>的相互转换,必须继承抽象类 XmlAdapter<ValueType,BoundType>
* ValueType能转换的类型
* BoundType不能转换的类型
* @author Kevin
*
*/
public class FKXMLAdapter extends XmlAdapter<StringCat, Map<String, Cat>> {

/**
* StringCat转换为Map<String, Cat>
*/
@Override
public Map<String, Cat> unmarshal(StringCat stringCat) throws Exception {
Map<String, Cat> map = new HashMap<String, Cat>();

for (Entry entry : stringCat.getEntryList()) {
map.put(entry.getKey(), entry.getValue());
}

return map;
}

/**
* Map<String, Cat>转换为StringCat
*/
@Override
public StringCat marshal(Map<String, Cat> map) throws Exception {
StringCat stringcat = new StringCat();
for (String key : map.keySet()) {
stringcat.getEntryList().add(new Entry(key, map.get(key)));
}
return stringcat;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐