Unable to parse the json

can anybody help
i am unable to parse the json array to be stored as a list

Please follow the reference links given in milestone tasks very aggressively. You can use the below link for reference.


Just go through the below link and you will similarities between the code that you are trying to write and the code given in the below link.
https://mkyong.com/java/jackson-how-to-parse-json/

i referd it but throws exceptions while debugging

what kind of exceptions are you facing ?

using the debuuger it navigates to a lot of exceptions in the ReflectionUtils.class

could you upload a screenshot or maybe post the stacktrace.

check if you have returned list in mainReadFile.
use debugger with stacktrace to solve the issue or find what exactly causing the issue.

Hey, I m also unable to parse JSON using objectMapper. I have created my Stock class and passing the JSON file and my Stock.class to readvalue. but getting given error:

11:03:36.135 [main] ERROR com.crio.warmup.stock.log.UncaughtExceptionHandler - {"stacktrace":["com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)","com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1442)","com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1216)","com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1168)","com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromArray(BeanDeserializerBase.java:1460)","com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:185)","com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:161)","com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4202)","com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3070)","com.crio.warmup.stock.PortfolioManagerApplication.mainReadFile(PortfolioManagerApplication.java:59)","com.crio.warmup.stock.PortfolioManagerApplication.main(PortfolioManagerApplication.java:139)"],"cause":"com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.crio.warmup.stock.PortfolioManagerApplication$Stock` out of START_ARRAY token\n at [Source: (File); line: 1, column: 1]"}
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.crio.warmup.stock.PortfolioManagerApplication$Stock` out of START_ARRAY token
 at [Source: (File); line: 1, column: 1]
        at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1442) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1216) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1168) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromArray(BeanDeserializerBase.java:1460) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:185) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:161) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4202) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3070) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.crio.warmup.stock.PortfolioManagerApplication.mainReadFile(PortfolioManagerApplication.java:59) ~[main/:?]
        at com.crio.warmup.stock.PortfolioManagerApplication.main(PortfolioManagerApplication.java:139) ~[main/:?]

Please help!!

Google this error. You will be able to figure out what to do. Remember that the readValue method from ObjectMapper can deserialize either an object, or array of objects. Check what your JSON file contains and deserialize accordingly.

The JSON file is provided with an array of objects. So while parsing please use make sure that you are your class object should be an array of objects.

Thanks for Help! Actually I was doing a silly mistake. :grimacing:

which is?
So that i wont do it !!!
:sweat_smile: :sweat_smile:

I hope you won’t do that :joy: I did some typo in the Stock class i created :yawning_face:

lol… now i have read the values using objectmapper.readvalue()
I dont have any idea on what to change it and return to the pringJsonoobject.
Any tips on what to do next?

There is nothing left if you got values from objectmapper, take a break :relieved: and then read TODO again, you will get to know what you need to return.

I dont know if i got the values from objectmapper. How to check that?

Use debugger and breakpoints.