{"action":"created","issue":{"url":"https://api.github.com/repos/dropwizard/dropwizard/issues/1297","labels_url":"https://api.github.com/repos/dropwizard/dropwizard/issues/1297/labels{/name}","comments_url":"https://api.github.com/repos/dropwizard/dropwizard/issues/1297/comments","events_url":"https://api.github.com/repos/dropwizard/dropwizard/issues/1297/events","html_url":"https://github.com/dropwizard/dropwizard/issues/1297","id":112974099,"number":1297,"title":"Optional Support for Dropwizard JDBI broken ","user":{"login":"pandaadb","id":15109364,"avatar_url":"https://avatars.githubusercontent.com/u/15109364?v=3","gravatar_id":"","url":"https://api.github.com/users/pandaadb","html_url":"https://github.com/pandaadb","followers_url":"https://api.github.com/users/pandaadb/followers","following_url":"https://api.github.com/users/pandaadb/following{/other_user}","gists_url":"https://api.github.com/users/pandaadb/gists{/gist_id}","starred_url":"https://api.github.com/users/pandaadb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pandaadb/subscriptions","organizations_url":"https://api.github.com/users/pandaadb/orgs","repos_url":"https://api.github.com/users/pandaadb/repos","events_url":"https://api.github.com/users/pandaadb/events{/privacy}","received_events_url":"https://api.github.com/users/pandaadb/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dropwizard/dropwizard/labels/bug","name":"bug","color":"e10c02"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/dropwizard/dropwizard/milestones/8","html_url":"https://github.com/dropwizard/dropwizard/milestones/0.9.0","labels_url":"https://api.github.com/repos/dropwizard/dropwizard/milestones/8/labels","id":1039133,"number":8,"title":"0.9.0","description":"","creator":{"login":"jplock","id":49093,"avatar_url":"https://avatars.githubusercontent.com/u/49093?v=3","gravatar_id":"","url":"https://api.github.com/users/jplock","html_url":"https://github.com/jplock","followers_url":"https://api.github.com/users/jplock/followers","following_url":"https://api.github.com/users/jplock/following{/other_user}","gists_url":"https://api.github.com/users/jplock/gists{/gist_id}","starred_url":"https://api.github.com/users/jplock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jplock/subscriptions","organizations_url":"https://api.github.com/users/jplock/orgs","repos_url":"https://api.github.com/users/jplock/repos","events_url":"https://api.github.com/users/jplock/events{/privacy}","received_events_url":"https://api.github.com/users/jplock/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":171,"state":"open","created_at":"2015-03-25T21:01:11Z","updated_at":"2015-10-28T10:37:03Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2015-10-23T08:20:10Z","updated_at":"2015-10-28T10:37:03Z","closed_at":"2015-10-28T10:37:03Z","body":"Hi,\r\n\r\nI recently noticed there is a bug in the optional handling for JDBi and joda DateTime objects. There is a serialisation issue that prevents any Optional datetimes to be inserted into a table. \r\n\r\nI created following unittest to demonstrate the problem:\r\n```java\r\npublic class TestJDBIOptional {\r\n\r\n\tprotected static DBI dbi;\r\n\tprotected static Environment env;\r\n\r\n\tstatic DataSourceFactory getDataSourceFactory() {\r\n\t\tDataSourceFactory dataSourceFactory = new DataSourceFactory();\r\n\t\tdataSourceFactory.setDriverClass(\"org.h2.Driver\");\r\n\t\tdataSourceFactory.setUrl(\"jdbc:h2:mem:testDb\");\r\n\t\tdataSourceFactory.setUser(\"sa\");\r\n\t\tdataSourceFactory.setPassword(\"\");\r\n\t\treturn dataSourceFactory;\r\n\t}\r\n\r\n\tString createTable = \"CREATE TABLE IF NOT EXISTS test ( id varchar(255) primary key, \"\r\n\t\t\t+ \" time timestamp);\";\r\n\r\n\t@Before\r\n\tpublic void setupTests() throws IOException {\r\n\t\tdbi.open().createStatement(createTable).execute();\r\n\t}\r\n\r\n\t@BeforeClass\r\n\tpublic static void setup() {\r\n\t\tenv = new Environment(\"test-env\", Jackson.newObjectMapper(), null, new MetricRegistry(), null);\r\n\t\tdbi = new DBIFactory().build(env, getDataSourceFactory(), \"test\");\r\n\t\tdbi.registerArgumentFactory(new JodaDateTimeArgumentFactory());\r\n\t\tdbi.registerMapper(new JodaDateTimeMapper(Optional.absent()));\r\n\t}\r\n\t\r\n\t@Test\r\n\tpublic void testInsert() {\r\n\t\tJDBIDao onDemand = dbi.onDemand(JDBIDao.class);\r\n\t\tonDemand.insert(Optional.of(DateTime.now()));\r\n\t}\r\n\r\n\t@Test \r\n\tpublic void testAbsent() {\r\n\t\tJDBIDao onDemand = dbi.onDemand(JDBIDao.class);\r\n\t\tonDemand.insert(Optional.absent());\r\n\t}\r\n\t\r\n\tpublic interface JDBIDao {\r\n\t\t \r\n\t\t@SqlUpdate(\"INSERT INTO test VALUES ('test', :ts)\")\r\n\t\tabstract int insert(@Bind(\"ts\") Optional<DateTime> dt);\r\n\t}\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/dropwizard/dropwizard/issues/comments/151795946","html_url":"https://github.com/dropwizard/dropwizard/issues/1297#issuecomment-151795946","issue_url":"https://api.github.com/repos/dropwizard/dropwizard/issues/1297","id":151795946,"user":{"login":"joschi","id":43951,"avatar_url":"https://avatars.githubusercontent.com/u/43951?v=3","gravatar_id":"","url":"https://api.github.com/users/joschi","html_url":"https://github.com/joschi","followers_url":"https://api.github.com/users/joschi/followers","following_url":"https://api.github.com/users/joschi/following{/other_user}","gists_url":"https://api.github.com/users/joschi/gists{/gist_id}","starred_url":"https://api.github.com/users/joschi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joschi/subscriptions","organizations_url":"https://api.github.com/users/joschi/orgs","repos_url":"https://api.github.com/users/joschi/repos","events_url":"https://api.github.com/users/joschi/events{/privacy}","received_events_url":"https://api.github.com/users/joschi/received_events","type":"User","site_admin":false},"created_at":"2015-10-28T10:37:03Z","updated_at":"2015-10-28T10:37:03Z","body":"Solved in #1304."}}