use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method testWriteToSingleQualifiedTag2.
@Test
public void testWriteToSingleQualifiedTag2() throws Exception {
JSONProvider<TagVO2> p = new JSONProvider<TagVO2>();
p.setNamespaceMap(Collections.singletonMap("http://tags", "ns1"));
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("{\"ns1.thetag\":{\"group\":\"b\",\"name\":\"a\"}}", s);
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method testAttributesAsElementsWithInteger.
@Test
public void testAttributesAsElementsWithInteger() throws Exception {
JSONProvider<TagVO2Holder> provider = new JSONProvider<TagVO2Holder>();
provider.setAttributesToElements(true);
provider.setIgnoreNamespaces(true);
TagVO2 tag = new TagVO2("A", "B");
tag.setAttrInt(123);
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\":{\"attrInt\":123,\"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 doTestWriteToSingleQualifiedTag.
private void doTestWriteToSingleQualifiedTag(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);
}
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("{\"ns1" + nsSep + "thetag\":{\"group\":\"b\",\"name\":\"a\"}}", s);
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method testInNsElementsFromLocals.
@Test
public void testInNsElementsFromLocals() throws Exception {
String data = "{tagholder:{thetag:{\"group\":\"B\",\"name\":\"A\"}}}";
JSONProvider<TagVO2Holder> provider = new JSONProvider<TagVO2Holder>();
Map<String, String> map = new HashMap<>();
map.put("tagholder", "{http://tags}tagholder");
map.put("thetag", "{http://tags}thetag");
provider.setInTransformElements(map);
ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
Object o = provider.readFrom(TagVO2Holder.class, TagVO2Holder.class, new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
TagVO2Holder holder = (TagVO2Holder) o;
TagVO2 tag2 = holder.getTagValue();
assertEquals("A", tag2.getName());
assertEquals("B", tag2.getGroup());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method readTagVO2AfterTransform.
private void readTagVO2AfterTransform(String data, String keyValue) throws Exception {
JSONProvider<TagVO2> provider = new JSONProvider<TagVO2>();
Map<String, String> map = new HashMap<>();
map.put(keyValue, "{http://tags}thetag");
Map<String, String> nsmap = new HashMap<>();
nsmap.put("http://bar", "t");
provider.setNamespaceMap(nsmap);
provider.setInTransformElements(map);
ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
Object o = provider.readFrom(TagVO2.class, TagVO2.class, new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(), is);
TagVO2 tag2 = (TagVO2) o;
assertEquals("A", tag2.getName());
assertEquals("B", tag2.getGroup());
}
Aggregations