Reputation:
I've tried to make a rest app that returns me a list of recipes, the count method works but the when I try to get one or all of them it gives me this error
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.util.ServiceConfigurationError: javax.json.bind.spi.JsonbProvider: Provider org.eclipse.yasson.JsonBindingProvider not found
I do have
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<version>1.0</version>
</dependency>
in my pom.xml
Function looks like this
@GET
@Path("/{id : \\d+}")
@Produces(APPLICATION_JSON)
public Response getBook(@PathParam("id") @Min(1) int id) {
Recipe recipe = recipeRepository.findOneByID(id);
if (recipe == null)
return Response.status(Response.Status.NOT_FOUND).build();
return Response.ok(recipe).build();
}
This is the function returning the recipe by ID
public Recipe findOneByID(int id) {
return entitymanager.find(Recipe.class, id);
}
And the recipe has the following attributes
@Id
private int id;
private String complexity;
private int cookingTime;
private String description;
private int estimatedTime;
private String imageUrl;
private String information;
private boolean isPromoted;
private int preparationTime;
private float servings;
private String title;
private String type;
//bi-directional many-to-one association to Allergen
@OneToMany(mappedBy="recipe")
private List<Allergen> allergens;
//bi-directional many-to-one association to Ingredient
@OneToMany(mappedBy="recipe")
private List<Ingredient> ingredients;
//bi-directional many-to-one association to Mediaitem
@OneToMany(mappedBy="recipe")
private List<Mediaitem> mediaitems;
//bi-directional many-to-one association to Nutritionvalue
@OneToMany(mappedBy="recipe")
private List<Nutritionvalue> nutritionvalues;
//bi-directional many-to-one association to Step
@OneToMany(mappedBy="recipe")
private List<Step> steps;
Any hint would be a huge help. I've spent half a day trying to fix this
Upvotes: 0
Views: 6625
Reputation: 4963
If you are running this on GlassFish 5.0-b11 or higher, then you need to remove your dependency on Yasson (since Yasson is already included in GlassFish 5 nightly builds after b11
), but you should specify a dependency on the JSON-B 1.0 API (and probably JSON-P 1.1 really) because there is no Java EE 8 umbrella dependency available yet to encompass all of the Java EE 8 specs.
Remove Yasson and add these:
<dependency>
<groupId>javax.json.bind</groupId>
<artifactId>javax.json.bind-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
Note that they need to have <scope>provided</scope>
, since GlassFish 5 is providing the implementation, and you don't want Maven to build the libraries into your app.
If you are using GlassFish 5.0-b10
or lower, then you need to specify these same dependencies as well as the Yasson dependency in your pom.xml above, since Yasson is the implementation and that needs to be present:
<dependency>
<groupId>javax.json.bind</groupId>
<artifactId>javax.json.bind-api</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
I have also explicitly added the <scope>compile</scope>
here, since that is the default if no scope is provided. It's sometimes useful to be explicit about this since you may want to move this project to GlassFish 5 in the future and the scope would need to be changed and the Yasson dependency removed completely.
Source: http://json-b.net/getting-started.html
Upvotes: 5