use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class EntityTypesTest method testJAXBListRepresentationFastInfoset.
/**
* TODO, the unmarshalling fails.
*/
@Test
@Ignore("TODO: unignore once fi support implemented (JERSEY-1190)")
public // TODO: unignore once fi support implemented (JERSEY-1190)
void testJAXBListRepresentationFastInfoset() {
final WebTarget target = target("JAXBListResourceFastInfoset");
Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
});
Collection<JaxbBean> b = target.request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/fastinfoset"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/fastinfoset"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
a = new LinkedList<>(a);
b = target.path("queue").request().post(Entity.entity(new GenericEntity<Queue<JaxbBean>>((Queue<JaxbBean>) a) {
}, "application/fastinfoset"), new GenericType<Queue<JaxbBean>>() {
});
assertEquals(a, b);
a = new HashSet<>(a);
b = target.path("set").request().post(Entity.entity(new GenericEntity<Set<JaxbBean>>((Set<JaxbBean>) a) {
}, "application/fastinfoset"), new GenericType<Set<JaxbBean>>() {
});
final Comparator<JaxbBean> c = new Comparator<JaxbBean>() {
@Override
public int compare(final JaxbBean t, final JaxbBean t1) {
return t.value.compareTo(t1.value);
}
};
final TreeSet<JaxbBean> t1 = new TreeSet<>(c);
final TreeSet<JaxbBean> t2 = new TreeSet<>(c);
t1.addAll(a);
t2.addAll(b);
assertEquals(t1, t2);
final Stack<JaxbBean> s = new Stack<>();
s.addAll(a);
b = target.path("stack").request().post(Entity.entity(new GenericEntity<Stack<JaxbBean>>(s) {
}, "application/fastinfoset"), new GenericType<Stack<JaxbBean>>() {
});
assertEquals(s, b);
a = new MyArrayList<>(a);
b = target.path("custom").request().post(Entity.entity(new GenericEntity<MyArrayList<JaxbBean>>((MyArrayList<JaxbBean>) a) {
}, "application/fastinfoset"), new GenericType<MyArrayList<JaxbBean>>() {
});
assertEquals(a, b);
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class EntityTypesTest method testJAXBListRepresentationJSONMediaType.
@Test
public void testJAXBListRepresentationJSONMediaType() throws Exception {
final WebTarget target = target("JAXBListResourceJSONMediaType");
final Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
});
Collection<JaxbBean> b = target.request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/foo+json"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/foo+json"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
// TODO: would be nice to produce/consume a real JSON array like following
// instead of what we have now:
// JSONArray a = r.get(JSONArray.class);
// JSONArray b = new JSONArray().
// put(new JSONObject().put("value", "one")).
// put(new JSONObject().put("value", "two")).
// put(new JSONObject().put("value", "three"));
// assertEquals(a.toString(), b.toString());
// JSONArray c = r.post(JSONArray.class, b);
// assertEquals(a.toString(), c.toString());
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class JsonMoxyTest method testJAXBListRepresentationJSONMediaType.
@Test
public void testJAXBListRepresentationJSONMediaType() throws Exception {
final WebTarget target = target("JAXBListResourceJSONMediaType");
final Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
});
Collection<JaxbBean> b = target.request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/foo+json"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/foo+json"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class JsonMoxyTest method testJAXBElementBeanJSONRepresentation.
@Test
public void testJAXBElementBeanJSONRepresentation() {
final WebTarget target = target("JAXBElementBeanJSONResource");
final GenericType<JAXBElement<String>> genericType = new GenericType<JAXBElement<String>>() {
};
final GenericEntity<JAXBElement<String>> jaxbElementGenericEntity = new GenericEntity<>(new JAXBElement<>(new QName("test"), String.class, "CONTENT"), genericType.getType());
final Response rib = target.request().post(Entity.entity(jaxbElementGenericEntity, "application/json"));
// TODO: the following would not be needed if i knew how to workaround JAXBElement<String>.class literal
final byte[] inBytes = getRequestEntity();
final byte[] outBytes = getEntityAsByteArray(rib);
assertEquals(new String(outBytes), inBytes.length, outBytes.length);
for (int i = 0; i < inBytes.length; i++) {
if (inBytes[i] != outBytes[i]) {
assertEquals("Index: " + i, inBytes[i], outBytes[i]);
}
}
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class JsonMoxyTest method testJAXBListRepresentationJSONLinkedList.
@Test
public void testJAXBListRepresentationJSONLinkedList() throws Exception {
final WebTarget target = target("JAXBListResourceJSON");
Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
});
final Collection<JaxbBean> b;
a = new LinkedList<>(a);
b = target.path("queue").request().post(Entity.entity(new GenericEntity<Queue<JaxbBean>>((Queue<JaxbBean>) a) {
}, "application/json"), new GenericType<Queue<JaxbBean>>() {
});
assertEquals(a, b);
}
Aggregations