第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

反序列化 Pojo 時(shí)如何忽略 JSON 根元素

反序列化 Pojo 時(shí)如何忽略 JSON 根元素

回首憶惘然 2023-07-19 15:49:09
==== 根對(duì)象 ====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}==== 庫(kù)存明細(xì)對(duì)象 ====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}====== 運(yùn)行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);       }    }另一個(gè)要求是如何更改大寫或小為 inventoryDetail 的根元素標(biāo)簽,使之像 InventoryDetail 一樣作為響應(yīng),我應(yīng)該以大寫或小開(kāi)頭
查看完整描述

1 回答

?
慕哥6287543

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超10個(gè)贊

import com.fasterxml.jackson.core.JsonGenerator;

import com.fasterxml.jackson.databind.JsonSerializable;

import com.fasterxml.jackson.databind.SerializerProvider;

import com.fasterxml.jackson.databind.jsontype.TypeSerializer;


import java.io.IOException;

import java.util.HashMap;

import java.util.Map;


public class RoomInventoryResponse implements JsonSerializable {



    private Map<String, InventoryDetail> inventoryDetail = new HashMap<>();


    public Map<String, InventoryDetail> getInventoryDetail() {

        return inventoryDetail;

    }


    public void setInventoryDetail(Map<String, InventoryDetail> inventoryDetail) {

        this.inventoryDetail = inventoryDetail;

    }


    @Override

    public void serialize(JsonGenerator arg0, SerializerProvider arg1) throws IOException {

        arg0.writeObject(inventoryDetail);

    }


    @Override

    public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException {


    }

}

對(duì)于你的最后一個(gè)問(wèn)題:


@JsonTypeName("InventoryDetail") // any name

@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT ,use = JsonTypeInfo.Id.NAME) 

    `


查看完整回答
反對(duì) 回復(fù) 2023-07-19
  • 1 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)