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

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

NamedList<Object> 拋出類轉(zhuǎn)換異常

NamedList<Object> 拋出類轉(zhuǎn)換異常

梵蒂岡之花 2023-07-28 15:39:41
我想形成一個(gè) NamedList 對(duì)象,如下所示:response={numFound=57279026,start=0,docs=[SolrDocument{timestamp_update=Thu Jan 01 01:00:00 CET 1970}]}}當(dāng)我這樣做時(shí),當(dāng)我的代碼嘗試訪問結(jié)果時(shí),我會(huì)拋出異常:SolrDocumentList results = response.getResults();**java.lang.ClassCastException: org.apache.solr.common.util.SimpleOrderedMap cannot be cast to org.apache.solr.common.SolrDocumentList**我應(yīng)該如何創(chuàng)建 NamedList,以便它不會(huì)引發(fā)異常這是我的做法:NamedList<Object> nl = new SimpleOrderedMap<>();private static  Map<String, Object> solrDocumentMap= new HashMap<>();solrDocumentMap.put("timestamp_update", TIMESTAMP_UPDATE);solrDocument= new SolrDocument(solrDocumentMap);solrDocumentList.add(solrDocument);nl.add("numFound", "57279026");nl.add("start", "0"); nl.add("docs", solrDocumentList); NamedList<Object> nl1 = new NamedList<>(Collections.singletonMap("response", nl)); response.setResponse(nl1);這是 QueryResponse 的內(nèi)置類,它將響應(yīng)轉(zhuǎn)換為 SolarDocument  public void setResponse(NamedList<Object> res) {        super.setResponse(res);        for(int i = 0; i < res.size(); ++i) {            String n = res.getName(i);            if ("responseHeader".equals(n)) {                this._header = (NamedList)res.getVal(i);            } else if ("response".equals(n)) {                this._results = (SolrDocumentList)res.getVal(i);            } else if ("sort_values".equals(n)) {                this._sortvalues = (NamedList)res.getVal(i);            } else if ("facet_counts".equals(n)) {                this._facetInfo = (NamedList)res.getVal(i);            } else if ("debug".equals(n)) {                this._debugInfo = (NamedList)res.getVal(i);                this.extractDebugInfo(this._debugInfo);            } 
查看完整描述

1 回答

?
牛魔王的故事

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

終于找到解決辦法了,希望對(duì)大家有幫助。我從 Solr 獲得了 XML 格式的響應(yīng),并讀取了該文件并使用 XMLResponseParser 對(duì)其進(jìn)行了解析。不知何故,JsonParser 不適用于 Solar,如果您使用 java 反序列化,Solr 中存在一個(gè)不兼容的錯(cuò)誤。


這也適用于查詢響應(yīng)類的內(nèi)部類型轉(zhuǎn)換。



protected QueryResponse getResponse(String fileName) throws IOException {


        Path path = Paths.get(resDir + "/" + fileName);

        InputStream body= new FileInputStream(path.toFile());

        NamedList<Object> result= processResponse(body, null);

        QueryResponse response = new QueryResponse();

        response.setResponse(result);

        return response;

    }


    private NamedList<Object> processResponse(InputStream body, Object o) {

        XMLResponseParser parser= new XMLResponseParser();

        NamedList<Object> result= parser.processResponse(body, "UTF-8");

        return result;

    }


查看完整回答
反對(duì) 回復(fù) 2023-07-28
  • 1 回答
  • 0 關(guān)注
  • 153 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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