Skip to content
Advertisement

Unable to receive data out of api call with webclient

So I’m trying to get my head around the webclient, but I keep getting a nullpointerexception, though my test work fine and say that object is not null. I also see my console making connection to the api. But when I ask the value, I get null.

Here are the two objects I use for it:

JavaScript
JavaScript

and then here I have my api call, I’ve put in my psvm to get console results:

JavaScript

But as a console output for the system.out.println I keep receiving: Exception in thread “main” java.lang.NullPointerException: Cannot invoke “be.hi10.apiesTest.domain.Data.getMessage()” because the return value of “be.hi10.apiesTest.domain.Foto.getData()” is null at be.hi10.apiesTest.ApiesTestApplication.main(ApiesTestApplication.java:31)

What am I doing wrong here? I should be receiving a String representing a url to an image.

Advertisement

Answer

Notice that your api returns response like this :

JavaScript

Since you are trying to convert your response to Foto class which looks like this :

JavaScript

For that to work your JSON should have to look like this :

JavaScript

but it doesnt and thats why your deserilization fails and you are getting NullPointerException.

To make this work, change response type to Data :

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement