Milestone 2 : Problem with getForObject method

I am not understanding this error:

  1. Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of com.crio.warmup.stock.dto.Candle (no Creators, like default construct, exist)

  2. Error are showing in line 744 and others lines, which even doesn’t exist in my code.

The total error was:

13:53:07.393 [main] ERROR com.crio.warmup.stock.log.UncaughtExceptionHandler - {“stacktrace”:[“org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:242)”,“org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:227)”,“org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:104)”,“org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)”,“org.springframework.web.client.RestTemplate.execute(RestTemplate.java:677)”,“org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:318)”,“com.crio.warmup.stock.PortfolioManagerApplication.mainReadQuotes(PortfolioManagerApplication.java:167)”,“com.crio.warmup.stock.PortfolioManagerApplication.main(PortfolioManagerApplication.java:204)”],“cause”:“org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class com.crio.warmup.stock.dto.Candle]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of com.crio.warmup.stock.dto.Candle (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (PushbackInputStream); line: 1, column: 2] (through reference chain: java.lang.Object[][0])”}
org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class com.crio.warmup.stock.dto.Candle]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of com.crio.warmup.stock.dto.Candle (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: (PushbackInputStream); line: 1, column: 2] (through reference chain: java.lang.Object[][0])
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:242) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:227) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:104) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:677) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:318) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at com.crio.warmup.stock.PortfolioManagerApplication.mainReadQuotes(PortfolioManagerApplication.java:167) ~[main/:?]
at com.crio.warmup.stock.PortfolioManagerApplication.main(PortfolioManagerApplication.java:204) ~[main/:?]
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of com.crio.warmup.stock.dto.Candle (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: (PushbackInputStream); line: 1, column: 2] (through reference chain: java.lang.Object[][0])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67) ~[jackson-databind-2.10.1.jar:2.10.1]
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1589) ~[jackson-databind-2.10.1.jar:2.10.1]
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1055) ~[jackson-databind-2.10.1.jar:2.10.1]
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:265) ~[jackson-databind-2.10.1.jar:2.10.1]
at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:195) ~[jackson-databind-2.10.1.jar:2.10.1]
at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:21) ~[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:3258) ~[jackson-databind-2.10.1.jar:2.10.1]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:239) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
… 7 more

I am stuck here since last night.
@Kiran @amanagar @AmoghaKS @Aravind_Menon

candle is an interface you cannot instantiate candle class

try to use tiingocandle instead

@vaibhavraj10 just go through this article understand interfaces and classes in java

Then check the directory where Candle interface is present there is also class named tiingocandle present use it.

Hey make sure you use TiingoCandle which is a class, Candle is an Interface which is not required now.
Refer to this FAQ, to solve your problem.

It was mentioned in TODO list to create list list<Candles> . So, I was confused and getting errors.

1 Like