Class<InterfaceWithMap> iwithMapClass = InterfaceWithMap.class;
Method method = iwithMapClass.getMethod("mapFunction");
Type mapType = method.getGenericReturnType();
AegisTestBean bean = new AegisTestBean();
bean.setBoolValue(Boolean.TRUE);
bean.setStrValue("hovercraft");
AegisSuperBean bean2 = new AegisSuperBean();
bean2.setBoolValue(Boolean.TRUE);
bean2.setStrValue("hovercraft2");
testMap.put(bean, bean2);
AegisJSONProvider writer = new AegisJSONProvider();
Map<String, String> namespaceMap = new HashMap<String, String>();
namespaceMap.put("urn:org.apache.cxf.aegis.types", "ns1");
namespaceMap.put("http://fortest.jaxrs.cxf.apache.org", "ns2");
writer.setNamespaceMap(namespaceMap);
ByteArrayOutputStream os = new ByteArrayOutputStream();
writer.writeTo(testMap, testMap.getClass(), mapType, null, null, null, os);
byte[] bytes = os.toByteArray();
String xml = new String(bytes, "utf-8");
String expected = "{\"ns1.AegisTestBean2AegisSuperBeanMap\":{\"@xsi.type\":"
+ "\"ns1:AegisTestBean2AegisSuperBeanMap\",\"ns1.entry\":{\"ns1.key\":{\"@xsi.type\":\"ns2:"
+ "AegisTestBean\",\"ns2.boolValue\":true,\"ns2.strValue\":\"hovercraft\"},\"ns1.value\":"
+ "{\"@xsi.type\":\"ns3:AegisSuperBean\",\"ns2.boolValue\":true,"
+ "\"ns2.strValue\":\"hovercraft2\"}}}}";
assertEquals(expected, xml);
AegisJSONProvider reader = new AegisJSONProvider();
Map<String, String> namespaceMap2 = new HashMap<String, String>();
namespaceMap2.put("urn:org.apache.cxf.aegis.types", "ns1");
namespaceMap2.put("http://fortest.jaxrs.cxf.apache.org", "ns2");
reader.setNamespaceMap(namespaceMap2);
byte[] simpleBytes = xml.getBytes("utf-8");
Object beanObject = reader.readFrom((Class)Map.class, mapType, null,
null, null, new ByteArrayInputStream(simpleBytes));
Map<AegisTestBean, AegisSuperBean> map2 = (Map)beanObject;
assertEquals(1, map2.size());
Map.Entry<AegisTestBean, AegisSuperBean> entry = map2.entrySet().iterator().next();
AegisTestBean bean1 = entry.getKey();
assertEquals("hovercraft", bean1.getStrValue());
assertEquals(Boolean.TRUE, bean1.getBoolValue());
AegisSuperBean bean22 = entry.getValue();
assertEquals("hovercraft2", bean22.getStrValue());
assertEquals(Boolean.TRUE, bean22.getBoolValue());
}