我们的中央银行以多种方式提供货币汇率。例如,日期上的一种货币很容易获得:http://api.nbp.pl/api/exchangerates/rates/a/usd/2020-08-20?format=json(它以简单的大括号开始{典型的Json(
但另一张表-每种货币的日期:http://api.nbp.pl/api/exchangerates/tables/a/2020-08-20?format=json在代码的行之后返回"nullSession">
if (httpURLConnection.getResponseCode() == okRespCode) { ...
尽管这个Json在webrowser中显示时没有任何问题。它以方括号[作为一个数组。
你见过并解决过这样的问题吗?
请从我的iDempire开发IDE中找到以下异常堆栈跟踪。
PM org.com.piere.process.SvrProcess process SEVERE:nullSession java.lang.NoSuchFieldError:位于的nullSessionsun.security.ssl.ClientHandshaker.getKickstartMessage(ClientHandshaker.java:1343(在sun.security.ssl.Handshaker.kickstart(Handshaker.java:1117(sun.security.ssl.SLSocketImpl.kickstartHandshake(SSLSocketImpl.java:1500(在sun.security.ssl.SLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367(在sun.security.ssl.SLSocketImpl.startHandshake(SSLSocketImpl.java:1416(在sun.security.ssl.SLSocketImpl.startHandshake(SSLSocketImpl.java:1400(在sun.net www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559(在sun.net www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractdeleteHttpsURLConnection.java:185(在sun.net www.protocol.HttpURLConnection.getInputStream0(HttpURLConnection.java:1570(在sun.net www.protocol.HttpURLConnection.getInputStream(HttpURLConnection.java:1498(在java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480(在sun.net www.protocol.httpsURLConnection Impl.getResponseCode(HttpsURLConnection impl.java:352(在one.sstabilit.utils.JsonUtils.readJsonToString(JsonUtils.java:75(在one.sstabilit.utils.JsonUtils.readArrayOfExchangeRatesTable(JsonUtils.java:108(在one.sstability.utils.JsonUtils.publishedOnDateTable(JsonUtils.java:55(在one.sstability.utils.JsonUtils.getPublishedOnDateTable(JsonUtils.java:32(在one.statibilit.impconvrates.ImportCurrencyRates.doIt(ImportCurrency Rates.java:84(网址:org.compiere.process.SvrProcess.produce(SvrProcess.java:201(org.compiere.process.SvrProcess.startProcess(SvrProcess.java:147(org.adempiere.util.ProcessUtil.startJavaProcess(ProcessUtil.java:172(在org.adempiere.util.ProcessUtil.startJavaProcess(ProcessUtil.java:139(在org.adempiere.util.ProcessUtil.startJavaProcess(ProcessUtil.java:128(在org.compiere.interfaces.impl.ServerBean.process(ServerBean.java:78(在org.compiere.apps.AbstractProcessCtl.startProcess(AbstractProcessCtl.java:429(在org.compiere.apps.AbstractProcessCtl.run(AbstractProcessCtl.java:234(网址:org.adempiere.webui.apps.WProcessCtr.proce(WProcessCtl.java:197(在org.adempiere.webui.apps.AbstractProcessDialog$ProcessDialogRunnable.doRun(AbstractProcessDialog.java:1083(网址:org.adempiere.util.ContextRunnable.run(ContextRunnable.java:38(在org.adempiere.webui.apps.DesktopRunnable.run(DesktopRunnable.java:40(在java.util.concurrent.Executors$RunnableAdapter.call(Executitors.java:511(位于java.util.concurrent.FFutureTask.run(FutureTask.java:266(java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180(在java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293(在java.util.concurrent.ThreadPoolExecutiator.runWorker(ThreadPoolExecutiator.java:1149(在java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624(在java.lang.Thread.run(Thread.java:748(
您可以将响应映射为List<JsonNode>
或List<CustomMapperObject>
。
由于响应本身是一个数组,而不是一个对象,因此可以执行类似的操作
String responseJson = "some array of objects";
List<CustomMapperObject> rates = objectMapper.readValue(responseJson,
ParameterizedTypeReference<List<CustomMapperObject>>() {
});
或
ResponseEntity<List<CustomMapperObject>> responseObject =
restTemplate.exchange(uri.toUriString(), HttpMethod.GET,
httpEntity,
new ParameterizedTypeReference<List<CustomMapperObject>>() {
});
我建议你去杰克逊图书馆看看,以供参考