使用非数据库字段自定义 Liferay Web 服务响应
Customize the Liferay Web Service response with non-database fields
在 Liferay 7 中,我用 getter/setter 的新字段自定义了我的 FooImpl.java(由服务构建器从 Foo table 生成):
@ProviderType
public class FooImpl extends FooBaseImpl {
private String toto;
// and getter and setter
public FooImpl() {
}
}
我添加此字段是因为我希望它出现在以下方法的 Web 服务响应中(摘自 FooServiceImpl.java):
@JSONWebService(value = "get-foos", method = "GET")
@AccessControlled(guestAccessEnabled=true)
public List<Foo> getFoos(){
...
}
很遗憾,JSON 响应不包含自定义字段 "toto"。
有人知道怎么做吗?
看看这个 wiki 页面。我对这个话题没有直接的经验。让我知道这是否正确。
非常感谢丹妮尔。
我在您提供的文档中找到了答案。
其实很简单,只要给你的模型对象加上注解@JSON(strict = false),所有的自定义属性都会被序列化。
@JSON(strict = false)
@ProviderType
public class FooImpl extends FooBaseImpl {
private String toto;
// and getter and setter
public FooImpl() {
}
}
在 Liferay 7 中,我用 getter/setter 的新字段自定义了我的 FooImpl.java(由服务构建器从 Foo table 生成):
@ProviderType
public class FooImpl extends FooBaseImpl {
private String toto;
// and getter and setter
public FooImpl() {
}
}
我添加此字段是因为我希望它出现在以下方法的 Web 服务响应中(摘自 FooServiceImpl.java):
@JSONWebService(value = "get-foos", method = "GET")
@AccessControlled(guestAccessEnabled=true)
public List<Foo> getFoos(){
...
}
很遗憾,JSON 响应不包含自定义字段 "toto"。
有人知道怎么做吗?
看看这个 wiki 页面。我对这个话题没有直接的经验。让我知道这是否正确。
非常感谢丹妮尔。 我在您提供的文档中找到了答案。
其实很简单,只要给你的模型对象加上注解@JSON(strict = false),所有的自定义属性都会被序列化。
@JSON(strict = false)
@ProviderType
public class FooImpl extends FooBaseImpl {
private String toto;
// and getter and setter
public FooImpl() {
}
}