0

Our Central Bank provides currency exchange rates in many ways. Ex. one currency on date is easy to get: http://api.nbp.pl/api/exchangerates/rates/a/usd/2020-08-20?format=json (It begins with simple brace { as typical Json)

but another table - each currency on date: http://api.nbp.pl/api/exchangerates/tables/a/2020-08-20?format=json returns 'nullSession' after line of the the code

    if (httpURLConnection.getResponseCode() == okRespCode) { ...

despite the fact that this Json is presented in webrowser without any problem. It begins with square bracket [ as an array.

Have you ever met and solved such an issue?

Please find below exception stack trace from my iDempiere development IDE.

PM org.compiere.process.SvrProcess process SEVERE: nullSession java.lang.NoSuchFieldError: nullSession at sun.security.ssl.ClientHandshaker.getKickstartMessage(ClientHandshaker.java:1343) at sun.security.ssl.Handshaker.kickstart(Handshaker.java:1117) at sun.security.ssl.SSLSocketImpl.kickstartHandshake(SSLSocketImpl.java:1500) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1416) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1400) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1570) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498) at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:352) at one.stabilis.utils.JsonUtils.readJsonToString(JsonUtils.java:75) at one.stabilis.utils.JsonUtils.readArrayOfExchangeRatesTable(JsonUtils.java:108) at one.stabilis.utils.JsonUtils.publishedOnDateTable(JsonUtils.java:55) at one.stabilis.utils.JsonUtils.getPublishedOnDateTable(JsonUtils.java:32) at one.stabilis.impconvrates.ImportCurrencyRates.doIt(ImportCurrencyRates.java:84) at org.compiere.process.SvrProcess.process(SvrProcess.java:201) at org.compiere.process.SvrProcess.startProcess(SvrProcess.java:147) at org.adempiere.util.ProcessUtil.startJavaProcess(ProcessUtil.java:172) at org.adempiere.util.ProcessUtil.startJavaProcess(ProcessUtil.java:139) at org.adempiere.util.ProcessUtil.startJavaProcess(ProcessUtil.java:128) at org.compiere.interfaces.impl.ServerBean.process(ServerBean.java:78) at org.compiere.apps.AbstractProcessCtl.startProcess(AbstractProcessCtl.java:429) at org.compiere.apps.AbstractProcessCtl.run(AbstractProcessCtl.java:234) at org.adempiere.webui.apps.WProcessCtl.process(WProcessCtl.java:197) at org.adempiere.webui.apps.AbstractProcessDialog$ProcessDialogRunnable.doRun(AbstractProcessDialog.java:1083) at org.adempiere.util.ContextRunnable.run(ContextRunnable.java:38) at org.adempiere.webui.apps.DesktopRunnable.run(DesktopRunnable.java:40) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

1 Answer 1

2

You can either map the response as List<JsonNode> or List<CustomMapperObject>.

Since the response is itself an array rather than an object, you can do something like this

String responseJson = "some array of objects";
List<CustomMapperObject> rates = objectMapper.readValue(responseJson, 
             ParameterizedTypeReference<List<CustomMapperObject>>() {
});

or

ResponseEntity<List<CustomMapperObject>> responseObject = 
                       restTemplate.exchange(uri.toUriString(), HttpMethod.GET,
                       httpEntity,
                       new ParameterizedTypeReference<List<CustomMapperObject>>() {
                       });

I would recommend to have a look at the Jackson Library for reference

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.