0
我想從一個POJO排除在POJO響應空字段
**** TransactionHistoryBO POJO的**排除空字段
package main.java.com.as.model;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TransactionHistoryBO
{
\t private String processId;
\t private String dateTime;
\t private Integer status;
\t private Double pointsEarned;
\t private String productName;
\t private String receiptNumber;
\t
\t public String getProcessId() {
\t \t return processId;
\t }
\t public void setProcessId(String processId) {
\t \t this.processId = processId;
\t }
\t public String getDateTime() {
\t \t return dateTime;
\t }
\t public void setDateTime(String dateTime) {
\t \t this.dateTime = dateTime;
\t }
\t public Integer getStatus() {
\t \t return status;
\t }
\t public void setStatus(Integer status) {
\t \t this.status = status;
\t }
\t
\t public Double getPointsEarned() {
\t \t return pointsEarned;
\t }
\t public void setPointsEarned(Double pointsEarned) {
\t \t this.pointsEarned = pointsEarned;
\t }
\t public String getProductName() {
\t \t return productName;
\t }
\t
\t public void setProductName(String productName) {
\t \t this.productName = productName;
\t }
\t
\t public String getReceiptNumber() {
\t \t return receiptNumber;
\t }
\t public void setReceiptNumber(String receiptNumber) {
\t \t this.receiptNumber = receiptNumber;
\t }
}
**
交易歷史回覆pojo
類型交易記錄BO的10public class TransactionHistoryResponse
{
\t private ArrayList<TransactionHistoryBO> transactions;
\t
\t @JsonInclude(JsonInclude.Include.NON_NULL)
\t public ArrayList<TransactionHistoryBO> getTransactions() {
\t \t return transactions;
\t }
\t @JsonInclude(Include.NON_NULL)
\t public void setTransactions(ArrayList<TransactionHistoryBO> transactions) {
\t \t this.transactions = transactions;
\t }
\t
\t }
數組列表在交易歷史響應pojo.This用的是我在response.I我出確切的POJO想排除與空值領域在交易歷史BO中。 我試着用@JsonInclude(JsonInclude.Include.NON_NULL)。它不工作.. 也試過用JsonSerialize,但它被棄用.Jackson使用的版本是2.2.2。
任何幫助將appreciated..please幫助..
,感謝您的幫助。在我原來的文章中,我聲明json在TransactionHistoryBO中的類級本身包含註釋。它無法正常工作。無論如何,我可以在寫作時使用對象映射器概念嗎?僅供參考:我正在使用rest。它會自動將pojo轉換爲json。 – Jill
您是否像在我的示例中那樣將jsoninclude註釋添加到TransactionHistoryResponse類中? – Ghokun
是的..它不工作.. – Jill