Ido_f Ido_f - 4 months ago 32
reST (reStructuredText) Question

Jersey Json and Pojo

I've spent far too many hours (over 10 i would say) trying to figure out how to get basic json calls (from angularjs) to open and process on my Jersey 2.4.
I've tried every possible result on google and am still getting a

415 (Unsupported Media Type)

client side and a

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/json, type=class jersey.webreadability.controllers.jsonmodels.TextInput, genericType=class jersey.webreadability.controllers.jsonmodels.TextInput.

on the server side.

I'll write here every possible file i've changed while trying to solve this, with the hope it will help someone to help me.
At the moment i don't really care how will it work as long as it will work, i do understand whoever that i should probably get this working with either Jackson or Gson.

Dependencies (from the POM File):


from the Web.xml:


The object class:

@XmlRootElement(name = "TextInput")
public class TextInput implements Serializable {

@XmlElement public String url;
@XmlElement public String text;
@XmlElement public String file;

public TextInput() {

public TextInput(String url, String text, String file) {
this.url = url;
this.text = text;
this.file = file;

public String toString() {
return "TextInput{" + "url=" + url + ", text=" + text + ", file=" + file +

main class:

public class AnalysisController {

public String sayHello(final TextInput text) {
System.out.println("printing out the sent text: " + text);

return "hello " + text.file;

and js:

var mockDataForThisTest = "json=" + encodeURI(JSON.stringify([
url: "",
text: "txext text tex",
file: $scope.textarea

var httpRequest = $http({
method: 'POST',
url: '/rest/analysisController/sayHello/',
data: mockDataForThisTest,
headers: {
'Content-Type': 'application/json'
}).success(function(data, status) {
$scope.textarea = data;
}).error(function(error) {

That's all I currently have, I hope it helps.

Thank you so very much.


I'm adding this as my own answer because i think this will help anyone with a horrible working copy of Jersey in the future. At the same time, the answer of @Michal Gajdos was grealy helpful and you should also relate to his text when having problems in the future.

What eventually helped me was a dependecy which includes pretty much every thing you need. simply add it and give it a try


source: Git