{"action":"created","issue":{"url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1413","repository_url":"https://api.github.com/repos/FasterXML/jackson-databind","labels_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1413/labels{/name}","comments_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1413/comments","events_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1413/events","html_url":"https://github.com/FasterXML/jackson-databind/issues/1413","id":182746826,"number":1413,"title":"Serialize InvalidFormatException cause infinite recursion","user":{"login":"inxi-pc","id":8216273,"avatar_url":"https://avatars.githubusercontent.com/u/8216273?v=3","gravatar_id":"","url":"https://api.github.com/users/inxi-pc","html_url":"https://github.com/inxi-pc","followers_url":"https://api.github.com/users/inxi-pc/followers","following_url":"https://api.github.com/users/inxi-pc/following{/other_user}","gists_url":"https://api.github.com/users/inxi-pc/gists{/gist_id}","starred_url":"https://api.github.com/users/inxi-pc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inxi-pc/subscriptions","organizations_url":"https://api.github.com/users/inxi-pc/orgs","repos_url":"https://api.github.com/users/inxi-pc/repos","events_url":"https://api.github.com/users/inxi-pc/events{/privacy}","received_events_url":"https://api.github.com/users/inxi-pc/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-10-13T10:01:13Z","updated_at":"2016-10-14T01:36:21Z","closed_at":"2016-10-14T01:10:54Z","body":"Jackson version: 2.8.1\r\n\r\nHi, \r\n\r\nI use jackson as a MessageBodyWriter and MessageBodyReader in jesery framwork. I am doing a \r\n\r\nrestful application. But I meet a terrible issue when i get InvalidFormatiotException and convert it \r\n\r\nto a response, `Infinite recursion (StackOverflowError)` error reporting! \r\n\r\n```\r\norg.glassfish.jersey.server.internal.process.MappableException: com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]->com.fasterxml.jackson.databind.ObjectMapper[\"factory\"]->com.fasterxml.jackson.databind.MappingJsonFactory[\"codec\"]\r\n```\r\nhave ignored very long repeat information.\r\n\r\n\r\nI have a POJO:\r\n\r\n```java\r\npublic class Post extends Domain {\r\n\r\n    @PrimaryKey\r\n    private Integer post_id;\r\n    private Integer category_id;\r\n    private Integer user_id;\r\n    private String post_title;\r\n    private String post_content;\r\n    private Boolean post_published;\r\n    private Boolean post_enabled;\r\n    private String post_created_at;\r\n    private String post_updated_at;\r\n\r\n    public Post() {\r\n        this.post_id = null;\r\n        this.category_id = null;\r\n        this.user_id = null;\r\n        this.post_title = null;\r\n        this.post_content = null;\r\n        this.post_published = null;\r\n        this.post_enabled = null;\r\n        this.post_created_at = null;\r\n        this.post_updated_at = null;\r\n    }\r\n\r\n    @JsonCreator\r\n    public Post(@JsonProperty(\"post_id\") Integer postId,\r\n                @JsonProperty(\"category_id\") Integer categoryId,\r\n                @JsonProperty(\"user_id\") Integer userId,\r\n                @JsonProperty(\"post_title\") String postTitle,\r\n                @JsonProperty(\"post_content\") String postContent,\r\n                @JsonProperty(\"post_published\") Boolean postPublished,\r\n                @JsonProperty(\"post_enabled\") Boolean postEnabled,\r\n                @JsonProperty(\"post_created_at\") String postCreatedAt,\r\n                @JsonProperty(\"post_updated_at\") String postUpdatedAt) {\r\n        this.post_id = postId;\r\n        this.category_id = categoryId;\r\n        this.user_id = userId;\r\n        this.post_title = postTitle;\r\n        this.post_content = postContent;\r\n        this.post_published = postPublished;\r\n        this.post_enabled = postEnabled;\r\n        this.post_created_at = postCreatedAt;\r\n        this.post_updated_at = postUpdatedAt;\r\n    }\r\n    // omit setter and getter\r\n}\r\n```\r\n\r\nIn normal situation, i transfer a normal json like `{\"post_id\": 1, \"post_title\": \"test\"'}`\r\n\r\n(I want to update a post), it works fine. But when i transfer a type mismatch json like \r\n\r\n`{\"post_id\": \"test\", \"post_title\": \"test\"'}`, the terrible situation appeared. \r\n\r\nI have a exception mapper to mapper a exception to a response, so in this case, when the type \r\n\r\nis mismatch, jackson will occur a InvalidFormatException:\r\n\r\n```java\r\ncom.fasterxml.jackson.databind.exc.InvalidFormatException: Can not deserialize value of type java.lang.Integer from String \"test\": not a valid Integer value\r\n at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@77d4bc0b; line: 2, column: 13] (through reference chain: myblog.domain.Post[\"post_id\"])\r\n\tat com.fasterxml.jackson.databind.exc.InvalidFormatException.from(InvalidFormatException.java:74)\r\n\tat com.fasterxml.jackson.databind.DeserializationContext.weirdStringException(DeserializationContext.java:1374)\r\n\tat com.fasterxml.jackson.databind.DeserializationContext.handleWeirdStringValue(DeserializationContext.java:925)\r\n\tat com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseInteger(StdDeserializer.java:454)\r\n\tat com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:308)\r\n\tat com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:286)\r\n\tat com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:490)\r\n\tat com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95)\r\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276)\r\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)\r\n\tat com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:1579)\r\n\tat com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:961)\r\n\tat com.fasterxml.jackson.jaxrs.base.ProviderBase.readFrom(ProviderBase.java:808)\r\n\tat org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:256)\r\n\tat org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:235)\r\n\tat org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155)\r\n\tat org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundReadFrom(MappableExceptionWrapperInterceptor.java:74)\r\n\tat org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155)\r\n\tat org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)\r\n\tat org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)\r\n\tat org.glassfish.jersey.server.ContainerRequest.readEntity(ContainerRequest.java:271)\r\n\tat org.glassfish.jersey.server.internal.inject.EntityParamValueFactoryProvider$EntityValueFactory.provide(EntityParamValueFactoryProvider.java:96)\r\n\tat org.glassfish.jersey.server.spi.internal.ParamValueFactoryWithSource.provide(ParamValueFactoryWithSource.java:71)\r\n\tat org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:94)\r\n\tat org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$AbstractMethodParamInvoker.getParamValues(JavaResourceMethodDispatcherProvider.java:127)\r\n\tat org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)\r\n\tat org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)\r\n\tat org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)\r\n\tat org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)\r\n\tat org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)\r\n\tat org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)\r\n\tat org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)\r\n\tat org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)\r\n\tat org.glassfish.jersey.internal.Errors.process(Errors.java:315)\r\n\tat org.glassfish.jersey.internal.Errors.process(Errors.java:297)\r\n\tat org.glassfish.jersey.internal.Errors.process(Errors.java:267)\r\n\tat org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)\r\n\tat org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)\r\n\tat org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)\r\n\tat org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:384)\r\n\tat org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:224)\r\n\tat org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)\r\n\tat org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)\r\n\tat java.lang.Thread.run(Thread.java:745)\r\n```\r\n\r\nAnd then i use a InternalServerException to pack this exception, and then set response entity by \r\n\r\nusing this new exception:\r\n\r\n```java\r\n@Provider\r\npublic class MyExceptionMapper implements ExceptionMapper<Exception> {\r\n\r\n    public Response toResponse(Exception ex) {\r\n\r\n\r\n        if (App.isDebug()) {\r\n            ex.printStackTrace();\r\n            return Response.status(500)\r\n                    .entity(ex)\r\n                    .type(MediaType.APPLICATION_JSON)\r\n                    .build();\r\n        } else {\r\n            return Response.status(500)\r\n                    .entity(ex)\r\n                    .type(MediaType.APPLICATION_JSON)\r\n                    .build();\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nThen, as you see, the infinite recursion appeared.  Why i get this terrible error?  If i dont pack the \r\n\r\nInvalidFormatException and use another exception to wrap the response entity, every thins is ok!\r\n\r\nHopeful to get the reply, i debugged whole day, StackOverFlow is really a disaster.\r\n\r\n\r\nThanks\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/comments/253687103","html_url":"https://github.com/FasterXML/jackson-databind/issues/1413#issuecomment-253687103","issue_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1413","id":253687103,"user":{"login":"inxi-pc","id":8216273,"avatar_url":"https://avatars.githubusercontent.com/u/8216273?v=3","gravatar_id":"","url":"https://api.github.com/users/inxi-pc","html_url":"https://github.com/inxi-pc","followers_url":"https://api.github.com/users/inxi-pc/followers","following_url":"https://api.github.com/users/inxi-pc/following{/other_user}","gists_url":"https://api.github.com/users/inxi-pc/gists{/gist_id}","starred_url":"https://api.github.com/users/inxi-pc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inxi-pc/subscriptions","organizations_url":"https://api.github.com/users/inxi-pc/orgs","repos_url":"https://api.github.com/users/inxi-pc/repos","events_url":"https://api.github.com/users/inxi-pc/events{/privacy}","received_events_url":"https://api.github.com/users/inxi-pc/received_events","type":"User","site_admin":false},"created_at":"2016-10-14T01:36:21Z","updated_at":"2016-10-14T01:36:21Z","body":"@cowtowncoder i checked #1368 patch content, @JsonIgnore added on the field _processor, in this case, the field _targetType is issue, so i think we need add @JsonIgnore on this field also.\r\n\r\nlet me try this version(2.8.3), and then reply here. Thanks! "}}
{"actor":{"display_login":"inxi-pc"}}