PageMapAdapter MapAdapter (续webServices)
public class PageMapAdapter extends XmlAdapter<PageMapConverter, IPage<Map<String, Object>>> { @Override public PageMapConverter marshal(IPage<Map<String, Object>> v) throws Exception { if(v == null){ return null; } PageMapConverter page = new PageMapConverter(); ArrayList<PageMapConverter.Entry[]> pageResult = new ArrayList<PageMapConverter.Entry[]>(); if(v.getResult() != null){ for (Map<String, Object> map : v.getResult()) { PageMapConverter.Entry[] object = new PageMapConverter.Entry[map.size()]; int i = 0; for (Map.Entry<String, Object> entry : map.entrySet()) { PageMapConverter.Entry mapEntry = new PageMapConverter.Entry(); mapEntry.setKey(entry.getKey()); if(entry.getValue() instanceof String){ mapEntry.setValue(EncodeUtil.urlEncode(entry.getValue().toString())); } else { mapEntry.setValue(entry.getValue()); } //System.out.println(mapEntry.getValue()); object[i++] = mapEntry; } pageResult.add(object); } } page.setResult(pageResult); page.setPageNo(v.getPageNo()); page.setPageSize(v.getPageSize()); page.setTotalCount(v.getTotalCount()); page.setAutoCount(v.isAutoCount()); page.setJumpNumber(v.getJumpNumber()); page.setOrder(v.getOrder()); page.setOrderBy(v.getOrderBy()); page.setTogglestatus(v.getTogglestatus()); page.setTotalPages(v.getTotalPages()); return page; } @Override public IPage<Map<String, Object>> unmarshal(PageMapConverter v) throws Exception { if(v == null){ return null; } Page<Map<String, Object>> page = new Page<Map<String, Object>>(); List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>(); Map<String, Object> map = null; if(v.getResult() != null){ for (PageMapConverter.Entry[] list : v.getResult()) { map = new HashMap<String, Object>(); for (PageMapConverter.Entry mapEntry : list) { if(mapEntry.getValue() instanceof String){ map.put(mapEntry.getKey(), EncodeUtil.urlDecode(mapEntry.getValue().toString())); } else if(mapEntry.getValue() instanceof XMLGregorianCalendarImpl){ XMLGregorianCalendarImpl date = (XMLGregorianCalendarImpl)mapEntry.getValue(); map.put(mapEntry.getKey(), date.toGregorianCalendar().getTime()); } else { map.put(mapEntry.getKey(), mapEntry.getValue()); } } mapList.add(map); } } page.setResult(mapList); page.setPageNo(v.getPageNo()); page.setPageSize(v.getPageSize()); page.setTotalCount(v.getTotalCount()); page.setTotalCount(v.getTotalCount()); page.setAutoCount(v.isAutoCount()); page.setJumpNumber(v.getJumpNumber()); //should not null or empty if(StringUtil.isNotEmpty(v.getOrder())){ page.setOrder(v.getOrder()); } page.setOrderBy(v.getOrderBy()); page.setTogglestatus(v.getTogglestatus()); page.setTotalPages(v.getTotalPages()); return page; } }
(2)MapAdapter
/** * Map适配器 * @author caosongqing * */ public class MapAdapter extends XmlAdapter<MapConverter, Map<String, Object>>{ @Override public MapConverter marshal(Map<String, Object> map) throws Exception { if(map == null){ return null; } MapConverter converter = new MapConverter(); for(Map.Entry<String, Object> entry:map.entrySet()){ MapConverter.MapEntry e = new MapConverter.MapEntry(); e.setKey(entry.getKey()); e.setValue(ConverterUtil.encode(entry.getValue())); converter.addEntry(e); } return converter; } @Override public Map<String, Object> unmarshal(MapConverter map) throws Exception { if(map == null){ return null; } Map<String, Object> result = new HashMap<String, Object>(); for(MapConverter.MapEntry e : map.getEntries()){ result.put(e.getKey(), ConverterUtil.decode(e.getValue())); } return result; } }