Just recently when I did a simple test on my JQuery-mobile page to print the result return from JAX-RS end point, I received an empty collection.
It says
localhost:8080 says: {"adjustmentInfo":[{}]}
At the same time, I am sure my end point returned a collection containing one AdjustmentInfo
object.
Here is my AdjustmentInfo
class.
// imports omitted @XmlRootElement // don't forget, required by JAX-RS public final class AdjustmentInfo implements Serializable { private long adjustmentNo; private String reason; private BigDecimal amount; private boolean negating; /** * Required by JAX-RS */ private AdjustmentInfo() { this.adjustmentNo = 0; this.reason = null; this.amount = null; this.negating = false; } AdjustmentInfo(final Adjustment adjustment) { this.adjustmentNo = adjustment.getAdjustmentNo(); this.reason = adjustment.getReason(); this.amount = adjustment.getAmount(); this.negating = adjustment.isNegating(); } public long getAdjustmentNo() { ... } public String getReason() { ... } public BigDecimal getAmount() { ... } public boolean isNegating() { ... } }
After trial-and-error, I found that apparently I had to implement all mutator method (I had not implemented it before because I didn’t have any need of them).
// imports omitted @XmlRootElement // don't forget, required by JAX-RS public final class AdjustmentInfo implements Serializable { private long adjustmentNo; private String reason; private BigDecimal amount; private boolean negating; /** * Required by JAX-RS */ private AdjustmentInfo() { this.adjustmentNo = 0; this.reason = null; this.amount = null; this.negating = false; } AdjustmentInfo(final Adjustment adjustment) { this.adjustmentNo = adjustment.getAdjustmentNo(); this.reason = adjustment.getReason(); this.amount = adjustment.getAmount(); this.negating = adjustment.isNegating(); } public long getAdjustmentNo() { ... } public String getReason() { ... } public BigDecimal getAmount() { ... } public boolean isNegating() { ... } // IMPLEMENT THESE MUTATORS public void setAdjustmentNo(long adjustmentNo) { ... } public void setReason(String reason) { ... } public void setAmount(BigDecimal amount) { ... } public void setNegating(boolean negating) { ... } }
Is it in the spec? I wonder…