'JAX-RS POJO to json does not work with payara 5

I have the following entity:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Recipe {

    private String title;
    private int preparationTime;

    public Recipe() {
    }

    public Recipe(String title, int preparationTime) {
        this.title = title;
        this.preparationTime = preparationTime;
    } 
}

and resource:

@Path("recipes")
@Stateless
public class RecipesResource {

    @GET
    public Recipe getRecipe() {
        return new Recipe("cake", 120);
    }
}

Requesting application/xml works fine and I get an xml object returned. Requesting application/json instead gives me an empty json object. If I add getter/setter to the Recipe class it also works for json.

My old setup with java-ee 7 and payara 4 worked fine without the getter/setters. I only changed to java-ee 8 and payara 5 and it does not work anymore, am I missing some configuration? Shouldn't @XmlAccessorType(XmlAccessType.FIELD) remove the necessity of getters/setters?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source