簡體   English   中英

使用非數據庫字段自定義Liferay Web Service響應

[英]Customize the Liferay Web Service response with non-database fields

在Liferay 7中,我使用帶有getter / setter的新字段自定義了FooImpl.java(由服務構建器從Foo表生成):

@ProviderType
public class FooImpl extends FooBaseImpl {

    private String toto;
    // and getter and setter

    public FooImpl() {
    }

}

我添加此字段是因為我希望在以下方法的Web Service響應中使用它(從FooServiceImpl.java中提取):

@JSONWebService(value = "get-foos", method = "GET")
@AccessControlled(guestAccessEnabled=true)
public List<Foo> getFoos(){
   ...
}

不幸的是,JSON響應不包含自定義字段“ toto”。

有人知道如何執行此操作嗎?

非常感謝Daniele。 我在您提供的文檔中找到了答案。

實際上,這非常簡單,只需將注釋@JSON(strict = false)添加到模型對象中,所有自定義屬性都將被序列化。

@JSON(strict = false)
@ProviderType
public class FooImpl extends FooBaseImpl {

    private String toto;
    // and getter and setter

    public FooImpl() {
    }

}

看看這個維基頁面。 我沒有這個主題的直接經驗。 讓我知道這是否是正確的方法。

https://web.liferay.com/it/community/wiki/-/wiki/Main/JSON+Serialization#section-JSON+Serialization-Strict+mode

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM