I'm trying to use Jersy 2 in client mode to post XML to a server but i always get an exception.
I have got only one dependency in my pom file:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.18</version>
</dependency>
My Java code:
public static void main(String... args) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080");
Entity<SimpleClass> entity = Entity.entity(new SimpleClass(), MediaType.APPLICATION_XML_TYPE);
target.request(MediaType.TEXT_XML_TYPE).post(entity);
}
@XmlRootElement(name = "test")
@XmlAccessorType(XmlAccessType.NONE)
public class SimpleClass {
@XmlElement(name = "hello")
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
Exception:
Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/xml, type=class jersey.SimpleClass, genericType=class jersey.SimpleClass.
What I'm doing wrong?