0

I'm trying to avoid getters and setters on my POJO but Jersey is using my getter methods to convert my POJO to JSON.

I tried using Yasson but when I tried to remove my getters it just returns blank JSON.

// the POJO
import javax.json.bind.annotation.JsonbProperty;
public final class LoginParameter {
  @JsonbProperty("endpoint")
  private String endPoint;
  @JsonbProperty("company-id")
  private String companyId;

  public LoginParameter() {
    endPoint = "";
    companyId = "";
  }

// trying to return JSON
final LoginParameter loginInfo = new LoginParameter();
        loginInfo.setCompanyId("test");
        loginInfo.setEndPoint("endpoint!");
return Response.status(Status.OK)
    .entity(jsonb.toJson(loginInfo))
    .type(MediaType.APPLICATION_JSON_TYPE).build();
Andy Guibert
  • 41,446
  • 8
  • 38
  • 61

1 Answers1

2

By default yasson doesn't serialize private members. In order for fields to be picked up either make them public, or add custom javax.json.bind.config.PropertyVisibilityStrategy to the runtime.

Roman Grigoriadi
  • 1,938
  • 14
  • 8