{"action":"created","issue":{"url":"https://api.github.com/repos/influxdata/influxdb-java/issues/540","repository_url":"https://api.github.com/repos/influxdata/influxdb-java","labels_url":"https://api.github.com/repos/influxdata/influxdb-java/issues/540/labels{/name}","comments_url":"https://api.github.com/repos/influxdata/influxdb-java/issues/540/comments","events_url":"https://api.github.com/repos/influxdata/influxdb-java/issues/540/events","html_url":"https://github.com/influxdata/influxdb-java/issues/540","id":378124910,"node_id":"MDU6SXNzdWUzNzgxMjQ5MTA=","number":540,"title":"InfluxDBResultMapper Can not set java.time.Instant field to POJO ","user":{"login":"liujingsheng","id":19465942,"node_id":"MDQ6VXNlcjE5NDY1OTQy","avatar_url":"https://avatars3.githubusercontent.com/u/19465942?v=4","gravatar_id":"","url":"https://api.github.com/users/liujingsheng","html_url":"https://github.com/liujingsheng","followers_url":"https://api.github.com/users/liujingsheng/followers","following_url":"https://api.github.com/users/liujingsheng/following{/other_user}","gists_url":"https://api.github.com/users/liujingsheng/gists{/gist_id}","starred_url":"https://api.github.com/users/liujingsheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liujingsheng/subscriptions","organizations_url":"https://api.github.com/users/liujingsheng/orgs","repos_url":"https://api.github.com/users/liujingsheng/repos","events_url":"https://api.github.com/users/liujingsheng/events{/privacy}","received_events_url":"https://api.github.com/users/liujingsheng/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-11-07T03:11:59Z","updated_at":"2018-11-08T11:46:26Z","closed_at":null,"author_association":"NONE","body":"Hi all,\r\nI use the influxDBResultMapper, but some times will shows error like this.\r\nI restart the program will be good, but run for a while it will shows the error:\r\nmy code like this, any one can help to check what's wrong.\r\n\r\nCan not set java.time.Instant field com.mango.firewaters.controllor.poco.Count.time to com.mango.firewaters.controllor.poco.Count\r\n\r\n```Java\r\npackage com.mango.firewaters.controllor;\r\n\r\nimport com.mango.firewaters.controllor.poco.Count;\r\nimport com.mango.firewaters.controllor.poco.EventResponse;\r\nimport com.mango.firewaters.influx.InfluxRepository;\r\nimport com.mango.firewaters.influx.data.InfluxSensorDataEntity;\r\nimport com.mango.firewaters.influx.data.InfluxSensorEventEntity;\r\nimport org.influxdb.InfluxDB;\r\nimport org.influxdb.dto.BoundParameterQuery.QueryBuilder;\r\nimport org.influxdb.dto.Query;\r\nimport org.influxdb.dto.QueryResult;\r\nimport org.influxdb.impl.InfluxDBResultMapper;\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\nimport java.text.DateFormat;\r\nimport java.text.ParseException;\r\nimport java.text.SimpleDateFormat;\r\nimport java.time.Instant;\r\nimport java.util.List;\r\nimport java.util.Locale;\r\n\r\n@RestController\r\n@RequestMapping(value = \"/api/\")\r\npublic class InfluxController {\r\n    private InfluxDBResultMapper resultMapper = new InfluxDBResultMapper(); // thread-safe - can be reused\r\n    private DateFormat dateFormat = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\", Locale.CHINA);\r\n    private InfluxDB influxDB;\r\n\r\n    public InfluxController(InfluxDB influxDB) {\r\n        this.influxDB = influxDB;\r\n\r\n    }\r\n\r\n    @GetMapping(\"/data\")\r\n    public List<InfluxSensorDataEntity> getSensorData(@RequestParam(value = \"sensorid\") String sensorid,\r\n                                                      @RequestParam(value = \"start\", required = false, defaultValue = \"\") String start,\r\n                                                      @RequestParam(value = \"end\", required = false, defaultValue = \"\") String end) {\r\n        Query query = null;\r\n\r\n        if (start.equals(\"\") && end.equals(\"\")) {\r\n            query = QueryBuilder.newQuery(\"SELECT * FROM sensordata WHERE sensorid = $sensorid\")\r\n                    .forDatabase(InfluxRepository.dbName)\r\n                    .bind(\"sensorid\", sensorid)\r\n                    .create();\r\n\r\n        } else if (!start.equals(\"\") && end.equals(\"\")) {\r\n            try {\r\n\r\n                Instant startTime = dateFormat.parse(start).toInstant();\r\n                query = QueryBuilder.newQuery(\"SELECT * FROM sensordata WHERE sensorid = $sensorid AND time >= $start\")\r\n                        .forDatabase(InfluxRepository.dbName)\r\n                        .bind(\"sensorid\", sensorid)\r\n                        .bind(\"start\", startTime)\r\n                        .create();\r\n            } catch (ParseException e) {\r\n                e.printStackTrace();\r\n            }\r\n\r\n\r\n        } else if (start.equals(\"\") && !end.equals(\"\")) {\r\n\r\n            try {\r\n\r\n                Instant endTime = dateFormat.parse(end).toInstant();\r\n                query = QueryBuilder.newQuery(\"SELECT * FROM sensordata WHERE sensorid = $sensorid AND time <= $end \")\r\n                        .forDatabase(InfluxRepository.dbName)\r\n                        .bind(\"sensorid\", sensorid)\r\n                        .bind(\"end\", endTime)\r\n                        .create();\r\n            } catch (ParseException e) {\r\n                e.printStackTrace();\r\n            }\r\n\r\n        } else if (!start.equals(\"\") && !end.equals(\"\")) {\r\n\r\n            try {\r\n                Instant startTime = dateFormat.parse(start).toInstant();\r\n                Instant endTime = dateFormat.parse(end).toInstant();\r\n                query = QueryBuilder.newQuery(\"SELECT * FROM sensordata WHERE sensorid = $sensorid AND time >= $start  AND time <= $end \")\r\n                        .forDatabase(InfluxRepository.dbName)\r\n                        .bind(\"sensorid\", sensorid)\r\n                        .bind(\"start\", startTime)\r\n                        .bind(\"end\", endTime)\r\n                        .create();\r\n            } catch (ParseException e) {\r\n                e.printStackTrace();\r\n            }\r\n\r\n\r\n        }\r\n\r\n        QueryResult results = influxDB.query(query);\r\n\r\n        return resultMapper.toPOJO(results, InfluxSensorDataEntity.class);\r\n\r\n    }\r\n\r\n    @GetMapping(\"/event\")\r\n    public EventResponse getSensorEvent(@RequestParam(value = \"sort\") String sort,@RequestParam(value = \"perpage\") String perpage, @RequestParam(value = \"page\") String page) {\r\n\r\n        int itemsPerPage = Integer.parseInt(perpage.trim());\r\n        int pageNumber = Integer.parseInt(page.trim());\r\n\r\n        Query query = QueryBuilder.newQuery(\"SELECT COUNT(value) FROM sensorevent\")\r\n                .forDatabase(InfluxRepository.dbName)\r\n                .create();\r\n\r\n        QueryResult results = influxDB.query(query);\r\n        List<Count> count = resultMapper.toPOJO(results, Count.class);\r\n        long totalCount = count.get(0).count;\r\n        long totalPage = (long) Math.ceil(totalCount / itemsPerPage);\r\n\r\n        query = QueryBuilder.newQuery(\"select * from sensorevent order by time \"+sort+\" limit \"+itemsPerPage+\" offset \"+(pageNumber*itemsPerPage))\r\n                .forDatabase(InfluxRepository.dbName)\r\n                .create();\r\n\r\n        results = influxDB.query(query);\r\n        List<InfluxSensorEventEntity> events = resultMapper.toPOJO(results, InfluxSensorEventEntity.class);\r\n\r\n        EventResponse eventResponse=new EventResponse();\r\n        eventResponse.setTotalCount(totalCount);\r\n        eventResponse.setPageNumber(pageNumber);\r\n        eventResponse.setTotalPage(totalPage);\r\n        eventResponse.setItemsPerPage(itemsPerPage);\r\n        eventResponse.setEvents(events);\r\n\r\n        return eventResponse;\r\n    }\r\n\r\n\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/influxdata/influxdb-java/issues/comments/436967762","html_url":"https://github.com/influxdata/influxdb-java/issues/540#issuecomment-436967762","issue_url":"https://api.github.com/repos/influxdata/influxdb-java/issues/540","id":436967762,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNjk2Nzc2Mg==","user":{"login":"fmachado","id":860287,"node_id":"MDQ6VXNlcjg2MDI4Nw==","avatar_url":"https://avatars1.githubusercontent.com/u/860287?v=4","gravatar_id":"","url":"https://api.github.com/users/fmachado","html_url":"https://github.com/fmachado","followers_url":"https://api.github.com/users/fmachado/followers","following_url":"https://api.github.com/users/fmachado/following{/other_user}","gists_url":"https://api.github.com/users/fmachado/gists{/gist_id}","starred_url":"https://api.github.com/users/fmachado/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fmachado/subscriptions","organizations_url":"https://api.github.com/users/fmachado/orgs","repos_url":"https://api.github.com/users/fmachado/repos","events_url":"https://api.github.com/users/fmachado/events{/privacy}","received_events_url":"https://api.github.com/users/fmachado/received_events","type":"User","site_admin":false},"created_at":"2018-11-08T11:46:26Z","updated_at":"2018-11-08T11:46:26Z","author_association":"CONTRIBUTOR","body":"@liujingsheng can you upgrade the influxdb-java library you are using to the version 2.14 and try again? This may be related with an old bug that was fixed some time ago.\r\n\r\nNote: not related with your original question but your REST entrypoint `/api/event` may be susceptible to SQL injection."}}
{"actor":{"display_login":"fmachado"}}