use of jakarta.xml.bind.JAXBElement in project spring-framework by spring-projects.
the class Jaxb2MarshallerTests method testSupports.
private void testSupports() throws Exception {
assertThat(marshaller.supports(Flights.class)).as("Jaxb2Marshaller does not support Flights class").isTrue();
assertThat(marshaller.supports((Type) Flights.class)).as("Jaxb2Marshaller does not support Flights generic type").isTrue();
assertThat(marshaller.supports(FlightType.class)).as("Jaxb2Marshaller supports FlightType class").isFalse();
assertThat(marshaller.supports((Type) FlightType.class)).as("Jaxb2Marshaller supports FlightType type").isFalse();
Method method = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
assertThat(marshaller.supports(method.getGenericReturnType())).as("Jaxb2Marshaller does not support JAXBElement<FlightsType>").isTrue();
marshaller.setSupportJaxbElementClass(true);
JAXBElement<FlightType> flightTypeJAXBElement = new JAXBElement<>(new QName("https://springframework.org", "flight"), FlightType.class, new FlightType());
assertThat(marshaller.supports(flightTypeJAXBElement.getClass())).as("Jaxb2Marshaller does not support JAXBElement<FlightsType>").isTrue();
assertThat(marshaller.supports(DummyRootElement.class)).as("Jaxb2Marshaller supports class not in context path").isFalse();
assertThat(marshaller.supports((Type) DummyRootElement.class)).as("Jaxb2Marshaller supports type not in context path").isFalse();
method = getClass().getDeclaredMethod("createDummyRootElement");
assertThat(marshaller.supports(method.getGenericReturnType())).as("Jaxb2Marshaller supports JAXBElement not in context path").isFalse();
assertThat(marshaller.supports(DummyType.class)).as("Jaxb2Marshaller supports class not in context path").isFalse();
assertThat(marshaller.supports((Type) DummyType.class)).as("Jaxb2Marshaller supports type not in context path").isFalse();
method = getClass().getDeclaredMethod("createDummyType");
assertThat(marshaller.supports(method.getGenericReturnType())).as("Jaxb2Marshaller supports JAXBElement not in context path").isFalse();
testSupportsPrimitives();
testSupportsStandardClasses();
}
use of jakarta.xml.bind.JAXBElement in project jaxrs-api by eclipse-ee4j.
the class MBWCheckResource method sendJAXBElement.
@GET
@Path("jaxbelement")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendJAXBElement(@Context SseEventSink sink, @Context Sse sse) {
try (SseEventSink s = sink) {
JAXBElement<String> element = new JAXBElement<String>(new QName("name"), String.class, MESSAGE);
s.send(sse.newEventBuilder().data(element).mediaType(MediaType.APPLICATION_XML_TYPE).build());
}
}
use of jakarta.xml.bind.JAXBElement in project jaxrs-api by eclipse-ee4j.
the class MediaTypeResource method sendJAXB.
@GET
@Path("jaxb")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendJAXB(@Context SseEventSink sink, @Context Sse sse) {
try (SseEventSink s = sink) {
JAXBElement<String> element = new JAXBElement<String>(new QName("name"), String.class, SSEMessage.MESSAGE);
s.send(sse.newEventBuilder().data(element).mediaType(mediaType).build());
}
}
use of jakarta.xml.bind.JAXBElement in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getJaxbToken.
private static String getJaxbToken() {
JAXBElement<String> element = new JAXBElement<String>(new QName("content"), String.class, plaincontent);
try {
JAXBContext context = JAXBContext.newInstance(String.class);
java.io.StringWriter writer = new java.io.StringWriter();
context.createMarshaller().marshal(element, writer);
return writer.toString();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
use of jakarta.xml.bind.JAXBElement in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method jaxbWriterClientInterceptorTest.
/*
* @testName: jaxbWriterClientInterceptorTest
*
* @assertion_ids: JAXRS:SPEC:84;
*
* @test_Strategy: JAX-RS implementations are REQUIRED to call registered
* interceptors when mapping representations to Java types and vice versa.
*/
@Test
@Tag("xml_binding")
public void jaxbWriterClientInterceptorTest() throws Fault {
JAXBElement<String> element = new JAXBElement<String>(new QName("element"), String.class, content);
GenericEntity<JAXBElement<String>> entity = new GenericEntity<JAXBElement<String>>(element) {
};
addProvider(EntityWriterInterceptor.class);
addInterceptors(EntityWriterInterceptor.class);
setRequestContentEntity(entity);
setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring"));
setProperty(Property.SEARCH_STRING, EntityWriterInterceptor.class.getName());
setProperty(Property.REQUEST_HEADERS, buildContentType(MediaType.TEXT_XML_TYPE));
setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION);
invoke();
logMsg("JAXRS called registered writer interceptor for JAXBElement provider");
}
Aggregations