use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method doReadQualifiedCollection.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void doReadQualifiedCollection(String data, boolean isArray) throws Exception {
JSONProvider provider = new JSONProvider();
Map<String, String> namespaceMap = new HashMap<>();
namespaceMap.put("http://tags", "ns1");
provider.setNamespaceMap(namespaceMap);
Method m = null;
if (!isArray) {
m = CollectionsResource.class.getMethod("setTags", new Class[] { List.class });
} else {
m = CollectionsResource.class.getMethod("setTagsArray", new Class[] { TagVO2[].class });
}
ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
Object o = provider.readFrom(m.getParameterTypes()[0], m.getGenericParameterTypes()[0], new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(), is);
assertNotNull(o);
TagVO2 t1 = null;
TagVO2 t2 = null;
if (!isArray) {
assertEquals(2, ((List<?>) o).size());
t1 = (TagVO2) ((List<?>) o).get(0);
t2 = (TagVO2) ((List<?>) o).get(1);
} else {
assertEquals(2, ((Object[]) o).length);
t1 = (TagVO2) ((Object[]) o)[0];
t2 = (TagVO2) ((Object[]) o)[1];
}
assertEquals("a", t1.getName());
assertEquals("b", t1.getGroup());
assertEquals("c", t2.getName());
assertEquals("d", t2.getGroup());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method testReadFromUnwrappedQualifiedTagRoot.
@Test
public void testReadFromUnwrappedQualifiedTagRoot() throws Exception {
JSONProvider<TagVO2> p = new JSONProvider<TagVO2>();
p.setSupportUnwrapped(true);
Map<String, String> namespaceMap = new HashMap<>();
namespaceMap.put("http://tags", "ns1");
p.setNamespaceMap(namespaceMap);
byte[] bytes = "{\"group\":\"b\",\"name\":\"a\"}".getBytes();
Object tagsObject = p.readFrom(TagVO2.class, null, null, null, null, new ByteArrayInputStream(bytes));
TagVO2 tag = (TagVO2) tagsObject;
assertEquals("a", tag.getName());
assertEquals("b", tag.getGroup());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method doTestReadFromQualifiedTag.
private void doTestReadFromQualifiedTag(String nsSep) throws Exception {
JSONProvider<TagVO2> p = new JSONProvider<TagVO2>();
Map<String, String> namespaceMap = new HashMap<>();
namespaceMap.put("http://tags", "ns1");
p.setNamespaceMap(namespaceMap);
if (!".".equals(nsSep)) {
p.setNamespaceSeparator(nsSep);
}
byte[] bytes = ("{\"ns1" + nsSep + "thetag\":{\"group\":\"b\",\"name\":\"a\"}}").getBytes();
Object tagsObject = p.readFrom(TagVO2.class, null, null, null, null, new ByteArrayInputStream(bytes));
TagVO2 tag = (TagVO2) tagsObject;
assertEquals("a", tag.getName());
assertEquals("b", tag.getGroup());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method testOutAppendElementsDiffNs.
@Test
public void testOutAppendElementsDiffNs() throws Exception {
JSONProvider<TagVO2> provider = new JSONProvider<TagVO2>();
Map<String, String> namespaceMap = new HashMap<>();
namespaceMap.put("http://tags", "ns2");
provider.setNamespaceMap(namespaceMap);
Map<String, String> map = new HashMap<>();
map.put("{http://tags}thetag", "{http://tagsvo2}t");
provider.setOutAppendElements(map);
TagVO2 tag = new TagVO2("A", "B");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
provider.writeTo(tag, TagVO2.class, TagVO2.class, new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
String expected = "{\"ps1.t\":{\"ns2.thetag\":{\"group\":\"B\",\"name\":\"A\"}}}";
assertEquals(expected, bos.toString());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method testWriteToSingleTag2NoNs.
@Test
public void testWriteToSingleTag2NoNs() throws Exception {
JSONProvider<TagVO2> p = new JSONProvider<TagVO2>();
p.setIgnoreNamespaces(true);
TagVO2 tag = createTag2("a", "b");
ByteArrayOutputStream os = new ByteArrayOutputStream();
p.writeTo(tag, TagVO2.class, TagVO2.class, TagVO2.class.getAnnotations(), MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os);
String s = os.toString();
assertEquals("{\"thetag\":{\"group\":\"b\",\"name\":\"a\"}}", s);
}
Aggregations