{"action":"closed","issue":{"url":"https://api.github.com/repos/square/moshi/issues/456","repository_url":"https://api.github.com/repos/square/moshi","labels_url":"https://api.github.com/repos/square/moshi/issues/456/labels{/name}","comments_url":"https://api.github.com/repos/square/moshi/issues/456/comments","events_url":"https://api.github.com/repos/square/moshi/issues/456/events","html_url":"https://github.com/square/moshi/issues/456","id":300558998,"number":456,"title":"Custom Type Adapters sometimes throws \"No @ToJson adapter for class annotated []\"","user":{"login":"rongi","id":7000897,"avatar_url":"https://avatars3.githubusercontent.com/u/7000897?v=4","gravatar_id":"","url":"https://api.github.com/users/rongi","html_url":"https://github.com/rongi","followers_url":"https://api.github.com/users/rongi/followers","following_url":"https://api.github.com/users/rongi/following{/other_user}","gists_url":"https://api.github.com/users/rongi/gists{/gist_id}","starred_url":"https://api.github.com/users/rongi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rongi/subscriptions","organizations_url":"https://api.github.com/users/rongi/orgs","repos_url":"https://api.github.com/users/rongi/repos","events_url":"https://api.github.com/users/rongi/events{/privacy}","received_events_url":"https://api.github.com/users/rongi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-02-27T09:48:44Z","updated_at":"2018-04-08T11:27:55Z","closed_at":"2018-04-08T11:27:55Z","author_association":"NONE","body":"This\r\n\r\n```kotlin\r\ndata class EventJson(\r\n  val date: String\r\n)\r\n\r\ndata class Event(\r\n  val date: Date\r\n)\r\n\r\nclass EventJsonAdapter {\r\n  @FromJson\r\n  fun eventFromJson(eventJson: EventJson): Event {\r\n    return Event(\r\n      date =  SimpleDateFormat(\"yyyy-MM-dd\", Locale.US).parse(eventJson.date)\r\n    )\r\n  }\r\n}\r\n\r\nprivate fun test() {\r\n  val moshi = Moshi.Builder()\r\n    .add(EventJsonAdapter())\r\n    .add(KotlinJsonAdapterFactory())\r\n    .build()\r\n\r\n  val jsonAdapter = moshi.adapter(Event::class.java)\r\n  val json = \"\"\"\r\n                {\r\n                  \"date\": \"2018-02-27\"\r\n                }\r\n             \"\"\"\r\n  Assert.assertEquals(\r\n    Event(date = SimpleDateFormat(\"yyyy-MM-dd\", Locale.US).parse(\"2018-02-27\")),\r\n    jsonAdapter.fromJson(json)\r\n  )\r\n}\r\n```\r\n\r\nwill produce \r\n\r\n```\r\njava.lang.IllegalArgumentException: No @ToJson adapter for class Event annotated []\r\n\r\n\tat com.squareup.moshi.AdapterMethodsFactory.create(AdapterMethodsFactory.java:52)\r\n\tat com.squareup.moshi.Moshi.adapter(Moshi.java:100)\r\n\tat com.squareup.moshi.Moshi.adapter(Moshi.java:62)\r\n\tat AlphaTestKtKt.test(AlphaTestKt.kt:33)\r\n\tat AlphaTestKtKt.access$test(AlphaTestKt.kt:1)\r\n\tat AlphaTestKt.testAlpha(AlphaTestKt.kt:49)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:498)\r\n\tat junit.framework.TestCase.runTest(TestCase.java:176)\r\n\tat junit.framework.TestCase.runBare(TestCase.java:141)\r\n\tat junit.framework.TestResult$1.protect(TestResult.java:122)\r\n\tat junit.framework.TestResult.runProtected(TestResult.java:142)\r\n\tat junit.framework.TestResult.run(TestResult.java:125)\r\n\tat junit.framework.TestCase.run(TestCase.java:129)\r\n\tat junit.framework.TestSuite.runTest(TestSuite.java:252)\r\n\tat junit.framework.TestSuite.run(TestSuite.java:247)\r\n\tat org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)\r\n\tat org.junit.runner.JUnitCore.run(JUnitCore.java:137)\r\n\tat org.junit.runner.JUnitCore.run(JUnitCore.java:115)\r\n\tat org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)\r\n\tat java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)\r\n\tat java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)\r\n\tat java.util.Iterator.forEachRemaining(Iterator.java:116)\r\n\tat java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)\r\n\tat java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)\r\n\tat java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)\r\n\tat java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)\r\n\tat java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)\r\n\tat java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)\r\n\tat java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)\r\n\tat org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:83)\r\n\tat org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:74)\r\n\tat org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)\r\n\tat org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)\r\n\tat org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)\r\n\tat com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:62)\r\n\tat com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)\r\n\tat com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)\r\n\tat com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:498)\r\n\tat com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)\r\n```\r\n\r\nAdding \"@ToJson\" will fix it. Making `Event.date` a `Long` instead of `Date` will fix it also.\r\n\r\nmoshi: 'com.squareup.moshi:moshi:1.5.0'\r\nmoshikotlin: 'com.squareup.moshi:moshi-kotlin:1.5.0'"}}
{"actor":{"display_login":"swankjesse"}}