==== 根对象 ====
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class RoomInventoryResponse {
private Map<String, InventoryDetail> inventoryDetail = new HashMap<>();
public Map<String, InventoryDetail> getInventoryDetail() {
return inventoryDetail;
}
public void setInventoryDetail(Map<String, InventoryDetail> inventoryDetail) {
this.inventoryDetail = inventoryDetail;
}
// To String overridden
}
==== 库存明细对象 ====
import java.util.Objects;
public class InventoryDetail {
private Integer booked;
private Integer available;
public Integer getBooked() {
return booked;
}
public void setBooked(Integer booked) {
this.booked = booked;
}
public Integer getAvailable() {
return available;
}
public void setAvailable(Integer available) {
this.available = available;
}
// To String overridden
}
====== 运行mentod ====
public class Test{
public static void main(String[] args) throws JsonProcessingException
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(request);
RoomInventoryResponse response = new RoomInventoryResponse();
Map<String, InventoryDetail> map = new HashMap<>();
InventoryDetail inventoryDetail = new InventoryDetail();
inventoryDetail.setAvailable(10);
inventoryDetail.setBooked(10);
map.put("2019-02-21", inventoryDetail);
InventoryDetail inventoryDetail2 = new InventoryDetail();
inventoryDetail2.setAvailable(15);
inventoryDetail2.setBooked(10);
map.put("2019-02-22", inventoryDetail2);
}
}
另一个要求是如何更改大写或小为 inventoryDetail 的根元素标签,使之像 InventoryDetail 一样作为响应,我应该以大写或小开头
慕哥6287543
相关分类