use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class XmlMoxyTest method testJAXBListRepresentationMediaType.
@Test
public void testJAXBListRepresentationMediaType() {
final WebTarget target = target("JAXBListResourceMediaType");
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+xml"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/foo+xml"), 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/foo+xml"), 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/foo+xml"), 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/foo+xml"), 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/foo+xml"), new GenericType<MyArrayList<JaxbBean>>() {
});
assertEquals(a, b);
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class EntityTypesTest method testJAXBListRepresentationMediaType.
@Test
public void testJAXBListRepresentationMediaType() {
final WebTarget target = target("JAXBListResourceMediaType");
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+xml"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/foo+xml"), 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/foo+xml"), 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/foo+xml"), 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/foo+xml"), 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/foo+xml"), new GenericType<MyArrayList<JaxbBean>>() {
});
assertEquals(a, b);
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class JsonMoxyTest method _testListOrArray.
@SuppressWarnings("unchecked")
public void _testListOrArray(final boolean isList, final MediaType mt) {
final Object in = isList ? getJAXBElementList() : getJAXBElementArray();
final GenericType gt = isList ? new GenericType<List<JAXBElement<String>>>() {
} : new GenericType<JAXBElement<String>[]>() {
};
final WebTarget target = target(isList ? "JAXBElementListResource" : "JAXBElementArrayResource");
final Object out = target.request(mt).post(Entity.entity(new GenericEntity(in, gt.getType()), mt), gt);
final List<JAXBElement<String>> inList = isList ? ((List<JAXBElement<String>>) in) : Arrays.asList((JAXBElement<String>[]) in);
final List<JAXBElement<String>> outList = isList ? ((List<JAXBElement<String>>) out) : Arrays.asList((JAXBElement<String>[]) out);
assertEquals("Lengths differ", inList.size(), outList.size());
for (int i = 0; i < inList.size(); i++) {
assertEquals("Names of elements at index " + i + " differ", inList.get(i).getName(), outList.get(i).getName());
assertEquals("Values of elements at index " + i + " differ", inList.get(i).getValue(), outList.get(i).getValue());
}
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class JsonMoxyTest method testJAXBListRepresentationJSONArrayList.
@Test
@Ignore("Until JERSEY-2825 is fixed.")
public void testJAXBListRepresentationJSONArrayList() throws Exception {
final WebTarget target = target("JAXBListResourceJSON");
Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
});
final Collection<JaxbBean> b;
a = new MyArrayList<>(a);
b = target.path("custom").request().post(Entity.entity(new GenericEntity<MyArrayList<JaxbBean>>((MyArrayList<JaxbBean>) a) {
}, "application/json"), new GenericType<MyArrayList<JaxbBean>>() {
});
assertEquals(a, b);
}
use of javax.ws.rs.core.GenericType in project opennms by OpenNMS.
the class RestClient method getEvents.
public List<OnmsEvent> getEvents() {
GenericType<List<OnmsEvent>> events = new GenericType<List<OnmsEvent>>() {
};
final WebTarget target = getTarget().path("events");
return getBuilder(target).get(events);
}
Aggregations