use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method testDropQualifiedElements.
@Test
public void testDropQualifiedElements() throws Exception {
JSONProvider<TagVO2> provider = new JSONProvider<TagVO2>();
List<String> list = new ArrayList<>();
list.add("{http://tags}thetag");
provider.setOutDropElements(list);
Map<String, String> map = new HashMap<>();
map.put("name", "");
provider.setOutTransformElements(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 = "{\"group\":\"B\"}";
assertEquals(expected, bos.toString());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method testOutElementsMapLocalNsToLocal.
@Test
public void testOutElementsMapLocalNsToLocal() throws Exception {
JSONProvider<TagVO2> provider = new JSONProvider<TagVO2>();
Map<String, String> map = new HashMap<>();
map.put("{http://tags}thetag", "t");
provider.setOutTransformElements(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 = "{\"t\":{\"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 testWriteArrayAndNamespaceOnObject.
@Test
public void testWriteArrayAndNamespaceOnObject() throws Exception {
JSONProvider<TagVO2> p = new JSONProvider<TagVO2>();
p.setIgnoreNamespaces(true);
p.setSerializeAsArray(true);
TagVO2 tag = new TagVO2("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);
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method testOutAttributesAsElements.
@Test
public void testOutAttributesAsElements() throws Exception {
JSONProvider<TagVO2Holder> provider = new JSONProvider<TagVO2Holder>();
Map<String, String> map = new HashMap<>();
map.put("{http://tags}thetag", "thetag");
map.put("{http://tags}tagholder", "tagholder");
provider.setOutTransformElements(map);
provider.setAttributesToElements(true);
TagVO2 tag = new TagVO2("A", "B");
TagVO2Holder holder = new TagVO2Holder();
holder.setTag(tag);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
provider.writeTo(holder, TagVO2Holder.class, TagVO2Holder.class, new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
String expected = "{\"tagholder\":{\"attr\":\"attribute\",\"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 testWriteToSingleQualifiedTagBadgerFish.
@Test
public void testWriteToSingleQualifiedTagBadgerFish() throws Exception {
JSONProvider<TagVO2> p = new JSONProvider<TagVO2>();
Map<String, String> namespaceMap = new HashMap<>();
namespaceMap.put("http://tags", "ns2");
p.setNamespaceMap(namespaceMap);
p.setConvention("badgerfish");
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("{\"ns2:thetag\":{\"@xmlns\":{\"ns2\":\"http:\\/\\/tags\"}," + "\"group\":{\"$\":\"b\"},\"name\":{\"$\":\"a\"}}}", s);
}
Aggregations