{"action":"created","issue":{"url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/2241","labels_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/2241/labels{/name}","comments_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/2241/comments","events_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/2241/events","html_url":"https://github.com/jhipster/generator-jhipster/issues/2241","id":113830467,"number":2241,"title":"[BUG] Elasticsearch throws exception deserializing LocalDate","user":{"login":"amitjindal","id":3275983,"avatar_url":"https://avatars.githubusercontent.com/u/3275983?v=3","gravatar_id":"","url":"https://api.github.com/users/amitjindal","html_url":"https://github.com/amitjindal","followers_url":"https://api.github.com/users/amitjindal/followers","following_url":"https://api.github.com/users/amitjindal/following{/other_user}","gists_url":"https://api.github.com/users/amitjindal/gists{/gist_id}","starred_url":"https://api.github.com/users/amitjindal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitjindal/subscriptions","organizations_url":"https://api.github.com/users/amitjindal/orgs","repos_url":"https://api.github.com/users/amitjindal/repos","events_url":"https://api.github.com/users/amitjindal/events{/privacy}","received_events_url":"https://api.github.com/users/amitjindal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-28T14:16:20Z","updated_at":"2015-10-28T18:00:47Z","closed_at":null,"body":"**Overview of the issue**\r\nWhen we try to deserialize an entity that was persisted to elasticsearch and has a member of type LocalDate it throws an exception.\r\n\r\nSearch for something that returns a empty result (running fine)\r\n```\r\n[DEBUG] com.mycompany.myapp.aop.logging.LoggingAspect - Enter: com.mycompany.myapp.web.rest.MyEntityResource.searchMyEntitys() with argument[s] = [First]\r\n[ERROR] com.mycompany.myapp.aop.logging.LoggingAspect - Exception in com.mycompany.myapp.web.rest.MyEntityResource.searchMyEntitys() with cause = com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class java.time.LocalDate]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)\r\n at [Source: {\"id\":1,\"name\":\"First\",\"startDate\":{\"year\":2014,\"month\":\"NOVEMBER\",\"dayOfMonth\":30,\"dayOfWeek\":\"SUNDAY\",\"era\":\"CE\",\"dayOfYear\":334,\"leapYear\":false,\"monthValue\":11,\"chronology\":{\"id\":\"ISO\",\"calendarType\":\"iso8601\"}}}; line: 1, column: 37] (through reference chain: com.mycompany.myapp.domain.MyEntity[\"startDate\"])\r\norg.springframework.data.elasticsearch.ElasticsearchException: failed to map source [ {\"id\":1,\"name\":\"First\",\"startDate\":{\"year\":2014,\"month\":\"NOVEMBER\",\"dayOfMonth\":30,\"dayOfWeek\":\"SUNDAY\",\"era\":\"CE\",\"dayOfYear\":334,\"leapYear\":false,\"monthValue\":11,\"chronology\":{\"id\":\"ISO\",\"calendarType\":\"iso8601\"}}}] to class MyEntity\r\n\tat org.springframework.data.elasticsearch.core.AbstractResultMapper.mapEntity(AbstractResultMapper.java:42) ~[spring-data-elasticsearch-1.3.0.RELEASE.jar:na]\r\n\tat org.springframework.data.elasticsearch.core.DefaultResultMapper.mapResults(DefaultResultMapper.java:83) ~[spring-data-elasticsearch-1.3.0.RELEASE.jar:na]\r\n\tat org.springframework.data.elasticsearch.core.ElasticsearchTemplate.queryForPage(ElasticsearchTemplate.java:265) ~[spring-data-elasticsearch-1.3.0.RELEASE.jar:na]\r\n\tat org.springframework.data.elasticsearch.core.ElasticsearchTemplate.queryForPage(ElasticsearchTemplate.java:259) ~[spring-data-elasticsearch-1.3.0.RELEASE.jar:na]\r\n\tat org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.search(AbstractElasticsearchRepository.java:197) ~[spring-data-elasticsearch-1.3.0.RELEASE.jar:na]\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_31]\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_31]\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_31]\r\n\tat java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_31]\r\n\tat org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:475) ~[spring-data-commons-1.11.0.RELEASE.jar:na]\r\n\tat org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:460) ~[spring-data-commons-1.11.0.RELEASE.jar:na]\r\n\tat org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:432) ~[spring-data-commons-1.11.0.RELEASE.jar:na]\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.2.RELEASE.jar:4.2.2.RELEASE]\r\n\tat org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.11.0.RELEASE.jar:na]\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.2.RELEASE.jar:4.2.2.RELEASE]\r\n\tat org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.2.RELEASE.jar:4.2.2.RELEASE]\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.2.RELEASE.jar:4.2.2.RELEASE]\r\n\tat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.2.2.RELEASE.jar:4.2.2.RELEASE]\r\n\tat com.sun.proxy.$Proxy186.search(Unknown Source) ~[na:na]\r\n\tat com.mycompany.myapp.web.rest.MyEntityResource.searchMyEntitys(MyEntityResource.java:149) ~[classes/:na]\r\n...\r\n```\r\n\r\n**JHipster Version(s)** \r\nLatest: 2.23.0\r\n\r\nYes, this is a regression. The deserializer is not able to deserialize new Java8 LocalDate.\r\n\r\n**JHipster configuration, a `.yo-rc.json` file generated in the root folder** \r\nAttached as Gist\r\nhttps://gist.github.com/amitjindal/e15a2124796f3fc5d047\r\n\r\n**Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory** \r\nAttached as Gist\r\nhttps://gist.github.com/amitjindal/e15a2124796f3fc5d047\r\n\r\n**Browsers and Operating System** \r\nAny\r\n\r\n**Reproduce the error** \r\nCreate 2-3 instances of myEntity. Then search for a name that should return one of the rows. On console you will see the exception.\r\n\r\n**Related issues** \r\nNone known.\r\n\r\n**Suggest a Fix** \r\nNot sure. Most likely we need to serialize properly or deserialize. Not sure why the default JavaTimeModule does not works. It might be that elasticsearch needs a different registration of this module.\r\n\r\nI've tried adding the JsonDeserialize(using = ...)\r\nbut that did not make a difference.\r\n"},"comment":{"url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/comments/151933768","html_url":"https://github.com/jhipster/generator-jhipster/issues/2241#issuecomment-151933768","issue_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/2241","id":151933768,"user":{"login":"cbornet","id":11633333,"avatar_url":"https://avatars.githubusercontent.com/u/11633333?v=3","gravatar_id":"","url":"https://api.github.com/users/cbornet","html_url":"https://github.com/cbornet","followers_url":"https://api.github.com/users/cbornet/followers","following_url":"https://api.github.com/users/cbornet/following{/other_user}","gists_url":"https://api.github.com/users/cbornet/gists{/gist_id}","starred_url":"https://api.github.com/users/cbornet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbornet/subscriptions","organizations_url":"https://api.github.com/users/cbornet/orgs","repos_url":"https://api.github.com/users/cbornet/repos","events_url":"https://api.github.com/users/cbornet/events{/privacy}","received_events_url":"https://api.github.com/users/cbornet/received_events","type":"User","site_admin":false},"created_at":"2015-10-28T18:00:47Z","updated_at":"2015-10-28T18:00:47Z","body":"Looks like spring-data-elasticsearch doesn't use Jackson2ObjectMapperBuilder to get its ObjectMapper and spring-boot doesn't change that either.\r\nCould you try following this ?\r\nhttps://github.com/spring-projects/spring-data-elasticsearch/wiki/Custom-ObjectMapper\r\n\r\nBut use something like:\r\n```java\r\npublic class CustomEntityMapper extends DefaultEntityMapper {\r\n\r\n    @Inject\r\n    private Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder;\r\n\r\n    public CustomEntityMapper () {\r\n        objectMapper = jackson2ObjectMapperBuilder.build();\r\n    }\r\n}\r\n```\r\n        \r\n        "}}