org.springframework.http.converter.HttpMessageNotReadableException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Carried over from SOCIAL-423: I tried the latest build but I get org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: No suitable constructor found for type [simple type, class org.springframework.social.facebook.api.FacebookProfile]: can not instantiate from JSON object (need to add/enable type information?) at [Source: java.io.ByteArrayInputStream@7e305fb2; line: 1, column: 2]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class org.springframework.social.facebook.api.FacebookProfile]: can not instantiate from JSON object (need to add/enable type information?) at [Source: java.io.ByteArrayInputStream@7e305fb2; line: 1, column: 2] at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:228) at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.read(MappingJackson2HttpMessageConverter.java:220) at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:95) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:549) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:517) at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:255) at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchObject(FacebookTemplate.java:165) at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:50) at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:46) exception
    via by Craig Walls,
  • GitHub comment 58#294182989
    via GitHub by athrane
    ,
  • Jackson JSON
    via by Unknown author,
  • Hi guys, I have the following JPA mapping: {code} @Entity public class Product { @ElementCollection(fetch = FetchType.LAZY) @CollectionTable(name = "product_name_lv", joinColumns = @JoinColumn(name = "product_pk")) @MapKeyColumn(name = "locale") @MapKeyJoinColumn(name = "language", referencedColumnName = "isocode") private Map<Locale, LocalizedValue> name = new HashMap<Locale, LocalizedValue>(); } {code} where the LocalizedValue is a simple POJO class: {code} @Embeddable public class LocalizedValue { @Column(name = "VALUE") private String value; } {code} So SDR works good and returns my product, like a normal json: {code} "name" : { "bg" : { "value" : "FOO" }, "en" : { "value" : "BAR" }, "de" : { "value" : "German FOO" } }, {code} So far so good I try to make a PUT request with the same json data, it yields with: {code} 2013-10-19 13:05:57,726 [qtp508751118-134] ERROR: Could not read JSON: Unrecognized field "en" (class com.xxxxxx.platform.core.model.i18n.LocalizedValue), not marked as ignorable (one known property: "value"]) at [Source: org.eclipse.jetty.server.HttpInput@63497f5b; line: 1, column: 30] (through reference chain: com.xxxxx.platform.core.model.i18n.LocalizedValue["en"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "en" (class com.xxxxxx.platform.core.model.i18n.LocalizedValue), not marked as ignorable (one known property: "value"]) at [Source: org.eclipse.jetty.server.HttpInput@63497f5b; line: 1, column: 30] (through reference chain: com.xxxxx.platform.core.model.i18n.LocalizedValue["en"]) org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unrecognized field "en" (class com.xxxxxx.platform.core.model.i18n.LocalizedValue), not marked as ignorable (one known property: "value"]) at [Source: org.eclipse.jetty.server.HttpInput@63497f5b; line: 1, column: 30] (through reference chain: com.xxxxxx.platform.core.model.i18n.LocalizedValue["en"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "en" (class com.xxxxxx.platform.core.model.i18n.LocalizedValue), not marked as ignorable (one known property: "value"]) at [Source: org.eclipse.jetty.server.HttpInput@63497f5b; line: 1, column: 30] (through reference chain: com.xxxxxx.platform.core.model.i18n.LocalizedValue["en"]) at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:181) at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readInternal(MappingJackson2HttpMessageConverter.java:166) at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:153) at org.springframework.data.rest.webmvc.PersistentEntityResourceHandlerMethodArgumentResolver.resolveArgument(PersistentEntityResourceHandlerMethodArgumentResolver.java:48) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:123) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:849) at javax.servlet.http.HttpServlet.service(HttpServlet.java:758) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482) at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482) at com.xxxxxx.platform.modules.rest.mvc.filter.CorsFilter.doFilterInternal(CorsFilter.java:23) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1474) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:499) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255) at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:370) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489) at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:960) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1021) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:722) {code} So I started digging in the code and I think the problem happens in PersistentEntityJackson2Module:197. I can see there an if-statement which checks if the property is of type map: {code} } else if (persistentProperty.isMap()) { Class<? extends Map<?, ?>> mtype = (Class<? extends Map<?, ?>>) persistentProperty.getType(); Map<Object, Object> m = (Map<Object, Object>) wrapper.getProperty(persistentProperty); if (null == m || m == Collections.EMPTY_MAP) { m = new HashMap<Object, Object>(); } if ((tok = jp.nextToken()) == JsonToken.START_OBJECT) { do { name = jp.getCurrentName(); // TODO resolve domain object from URI tok = jp.nextToken(); Object mval = jp.readValueAs(persistentProperty.getMapValueType()); //<-- this line reads as persistent property map value type. m.put(name, mval); } while ((tok = jp.nextToken()) != JsonToken.END_OBJECT); val = m; } else if (tok == JsonToken.VALUE_NULL) { val = null; } else { throw new HttpMessageNotReadableException("Cannot read a JSON " + tok + " as a Map."); } {code} So it basically gets the type of the persistent property, creates an empty map, iterates over the json, and reads the value of the original map (i.e. what will be placed after name: ) as the value of the persistent property map (LocalizedValue in my case). Which is wrong I think. It should read it as a map imho.
    via by Petar Tahchiev,
    • org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: No suitable constructor found for type [simple type, class org.springframework.social.facebook.api.FacebookProfile]: can not instantiate from JSON object (need to add/enable type information?) at [Source: java.io.ByteArrayInputStream@7e305fb2; line: 1, column: 2]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class org.springframework.social.facebook.api.FacebookProfile]: can not instantiate from JSON object (need to add/enable type information?) at [Source: java.io.ByteArrayInputStream@7e305fb2; line: 1, column: 2] at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:228) at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.read(MappingJackson2HttpMessageConverter.java:220) at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:95) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:549) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:517) at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:255) at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchObject(FacebookTemplate.java:165) at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:50) at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:46)

    Users with the same issue

    tvrmsmithtvrmsmith
    3 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,