简体   繁体   English

我是否需要使用Yasson进行JSON绑定的吸气剂?

[英]Do I need getters on JSON binding with Yasson?

I'm trying to avoid getters and setters on my POJO but Jersey is using my getter methods to convert my POJO to JSON. 我正在尝试避免在POJO上使用getter和setter,但是Jersey正在使用我的getter方法将POJO转换为JSON。

I tried using Yasson but when I tried to remove my getters it just returns blank JSON. 我尝试使用Yasson,但是当我尝试删除自己的吸气剂时,它只会返回空白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();

By default yasson doesn't serialize private members. 默认情况下,yasson不会序列化私有成员。 In order for fields to be picked up either make them public, or add custom javax.json.bind.config.PropertyVisibilityStrategy to the runtime. 为了使字段成为公共字段,或将自定义javax.json.bind.config.PropertyVisibilityStrategy添加到运行时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM