Я только начинаю изучать веб-службы Restful и работаю над заданием, в котором мне нужно возвращать подробности объекта класса Product при вызове определенного метода GET.
Я хочу отправить обратно - {"product_id": 123," цена ": 35.50," валюта ":" SGD "," total_items ": 1000," items_left ": 450," time_left ": 100000}
Однако я получаю ответ как(Обратите внимание на дубликаты) - {"availableQuantity": 45, "currency": "SGD", "items_left": 45, "price": 35.5, "product_id": 1, "productId": 1, "time_left": 10000, "timeAvailable": 10000, "total_items": 100, "totalItems": 100}
Мой класс продукта: -
public class Product {
@XmlAttribute(name = "product_id")
private int productId;
private double price;
private String currency;
@XmlAttribute(name = "total_items")
private int totalItems;
public int getTotalItems() {
return totalItems;
}
public void setTotalItems(int totalItems) {
this.totalItems = totalItems;
}
@XmlAttribute(name = "items_left")
private int availableQuantity;
@XmlAttribute(name = "time_left")
private long timeAvailable;
public int getProductId() {
return productId;
}
public void setProductId(int productId) {
this.productId = productId;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
public int getAvailableQuantity() {
return availableQuantity;
}
public void setAvailableQuantity(int availableQuantity) {
this.availableQuantity = availableQuantity;
}
public long getTimeAvailable() {
return timeAvailable;
}
public void setTimeAvailable(long timeAvailable) {
this.timeAvailable = timeAvailable;
}
public Product(int id, double price, String currency, int totalItems, int itemsLeft, long timeLeft) {
this.productId = id;
this.price = price;
this.currency = currency;
this.totalItems = totalItems;
this.availableQuantity = itemsLeft;
this.timeAvailable = timeLeft;
}
}
Как удалить дубликаты и вернуть ожидаемые значения(хотя мои переменные класса имеют другое имя)?Извиняюсь за любую неверную / недостающую информацию!