Unrecognized Property Exception for "2. high"

This error comes when i try to map the API result with the AlphavantageDailyResponse object
What should I do to correct this?
The api result has keys as “1. open”, “2. high” and our POJO class has keys as open, high…

@TanG Please refer to the following references

Read about jackson annotations.

Hi @TanG,

I think you have made an error in unmarshalling the properties of the API. I suggest you check the API response once, see which one has been incorrectly marshalled and correct it. Shouldn’t be too difficult to resolve.

Let me know if it helps!

@TanG use Jackson annotation @JsonProperty on pojo data members which are to be mapped with corresponding json objects.
A sample example is already given in the code snippet.

I am mapping the result of API call to AlphavantageDailyResponse , from that I get the map using getCandles() and then traversing the map and creating AlphavantageCandle objects and adding it to the list and returning that.

What I am doing wrong in the process??

I think the annotation number during unmarshalling may be incorrect. For example, high may not be “2. High”.

Just check it once for all properties. And remember that date cannot be unmarshalled directly. So you need to leave that.

@TanG I think the error is coming because of your provided keys.

Let me give you a hint.

Remember when you pulled out the stubs, the file AlphavantageCandle had some code and some links for hints in it:

Code Hint

@JsonProperty("1. open")

Reference Links

https:www.baeldung.com/jackson-ignore-properties-on-serialization

https:www.baeldung.com/jackson-name-of-property

I suggest you read the stuff from the provided link to find out what @JsonProperty(“1. open”) is doing, and why you are getting the mismatching exception.

All the best :slight_smile:

Thank you for your response.
Solved that already but encountering a new error :

hello…i am facing the same issue u had encountered i m getting a null in in the object of AlphaVantageResponse when i tried to deserilaise response string to this class…i had set jsonproperty() in my Alphavintagecandle cclass for open,close,high ,low…do we need to do something for date too…or is it fine…also do we need to filter that (metadata part form the response string sot that at final we have a string of only dates and its corresponding values of open ,close ,high low)…plz help i have been stuck for 2 days

@aakarsh2126 please follow the following thread

Thread

Null pointer exception when I run the spring boot app

its not that i m not getting anything from rest template…i got a string which has all stock details…its same as by postman…i m facing issue regarding de serialisiing it in AlphaVinatageResponse…i had read the whole above thread regarding adding jsonProperty() to your member variables in AlphaVintageCandle class…but still somehow i m getting null when i tried to access getCandles() method of AlphaVinatageresponse

@aakarsh2126 I think you’re having some problem with deserialization of Nested-JSON string and as a result, the returned template is giving you the null objects.

I was also tackling the same problem.

Here are the following references I followed

Link 1: https://stackoverflow.com/questions/11747370/jackson-how-to-process-deserialize-nested-json

Link 2: https://www.baeldung.com/jackson-nested-values

Link 3: https://stackoverflow.com/questions/47263236/how-to-parse-json-object-array-with-jackson-into-dto-in-springboot

Link 4: https://www.journaldev.com/2324/jackson-json-java-parser-api-example-tutorial

Hope It’ll Help, all the best :slight_smile:

is there is some error in deserialising date??

@aakarsh2126 which keyword you used in your POJO for date ?

@JsonDeserializer…i put it just above localdate… Do we need to Put something else

Take a look at your deserializer or the structure of the POJO. Something is weird with them.


i am getting this error now…Deserialising on AlphaVintageDailyResonse has still got null…i had now added @JsonIgnoreProperties() at the top of begining of AlphaVindategCandle class to ignore some fields and also used @JsonFormat() for date…error is now arry out of bounds…since getting null…when accessing getCandles()

dont’ worry that issue is resolved…but now i am getting wrong answer…dow we need to sort candle???i mean isnt it already sorted during map…if not how to sort…since candle is interface…we cant sort candle by implementing Comparable<> and AlphavintageCandle too since it implements Candle…

finally resolved this issue completey…test successful…thanks a lot everyone…

1 Like