0

I am currently implementing a API through Jersey. In the below code I have a class with a GET operation which returns a float. When I call this method I am getting the below error message :

MessageBodyWriter not found for media type=application/json, type=class 
java.lang.Float, genericType=float.

Now I have googled around and the general consensus is that either I do not have a default constructor on my model class, I don't have the correct dependency (notably the : org.glassfish.jersey.media) or I don't have the correct annotation on my class. I have all these however.

Strangely, all of my other end points are working as expected in the same class, any help would be greatly appreciated!

Model Class

  @XmlRootElement
  public class Product {

    private float pprice;

    public Project(){}

    public Project(float pprice)
    {
        this.pprice = pprice;
    }
    // relevant getter and setters
  }

Endpoint class

    @Path("/product")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public class ProductS {

    @GET
    @Path("/products/{productID}")
    public float getAccountBalance(@PathParam("productID") int productID){
        float b =  ps.getb(productID);
        return b;
    }

}

Note, the rest of my endpoints work as expected, just this call pops that error

GrandeurH
  • 147
  • 1
  • 1
  • 13

0 Answers0