{"action":"opened","issue":{"url":"https://api.github.com/repos/square/moshi/issues/617","repository_url":"https://api.github.com/repos/square/moshi","labels_url":"https://api.github.com/repos/square/moshi/issues/617/labels{/name}","comments_url":"https://api.github.com/repos/square/moshi/issues/617/comments","events_url":"https://api.github.com/repos/square/moshi/issues/617/events","html_url":"https://github.com/square/moshi/issues/617","id":349407775,"node_id":"MDU6SXNzdWUzNDk0MDc3NzU=","number":617,"title":"Any documents for @FromJson and @ToJson?","user":{"login":"jaychang0917","id":5347535,"node_id":"MDQ6VXNlcjUzNDc1MzU=","avatar_url":"https://avatars2.githubusercontent.com/u/5347535?v=4","gravatar_id":"","url":"https://api.github.com/users/jaychang0917","html_url":"https://github.com/jaychang0917","followers_url":"https://api.github.com/users/jaychang0917/followers","following_url":"https://api.github.com/users/jaychang0917/following{/other_user}","gists_url":"https://api.github.com/users/jaychang0917/gists{/gist_id}","starred_url":"https://api.github.com/users/jaychang0917/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaychang0917/subscriptions","organizations_url":"https://api.github.com/users/jaychang0917/orgs","repos_url":"https://api.github.com/users/jaychang0917/repos","events_url":"https://api.github.com/users/jaychang0917/events{/privacy}","received_events_url":"https://api.github.com/users/jaychang0917/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-10T07:37:43Z","updated_at":"2018-08-10T07:37:43Z","closed_at":null,"author_association":"NONE","body":"I was wondering what the **signatures for method annotated `@FromJson` or `ToJson`** are. Are there any documents for them? When I was looking at the [MultipleFormats adapter](https://github.com/square/moshi/blob/master/examples/src/main/java/com/squareup/moshi/recipes/MultipleFormats.java) parsing multiple formats of JSON, I was totally lost.\r\n\r\nThanks in advanced.\r\n```java\r\n/** Handles cards either as strings \"5D\" or as objects {\"suit\": \"SPADES\", \"rank\": 5}. */\r\n  public final class MultipleFormatsCardAdapter {\r\n    @ToJson void toJson(JsonWriter writer, Card value,\r\n        @CardString JsonAdapter<Card> stringAdapter) throws IOException {\r\n      stringAdapter.toJson(writer, value);\r\n    }\r\n\r\n    @FromJson Card fromJson(JsonReader reader, @CardString JsonAdapter<Card> stringAdapter,\r\n        JsonAdapter<Card> defaultAdapter) throws IOException {\r\n      if (reader.peek() == JsonReader.Token.STRING) {\r\n        return stringAdapter.fromJson(reader);\r\n      } else {\r\n        return defaultAdapter.fromJson(reader);\r\n      }\r\n    }\r\n  }\r\n\r\n  /** Handles cards as strings only. */\r\n  public final class CardStringAdapter {\r\n    @ToJson String toJson(@CardString Card card) {\r\n      return card.rank + card.suit.name().substring(0, 1);\r\n    }\r\n\r\n    @FromJson @CardString Card fromJson(String card) {\r\n      if (card.length() != 2) throw new JsonDataException(\"Unknown card: \" + card);\r\n\r\n      char rank = card.charAt(0);\r\n      switch (card.charAt(1)) {\r\n        case 'C': return new Card(rank, Suit.CLUBS);\r\n        case 'D': return new Card(rank, Suit.DIAMONDS);\r\n        case 'H': return new Card(rank, Suit.HEARTS);\r\n        case 'S': return new Card(rank, Suit.SPADES);\r\n        default: throw new JsonDataException(\"unknown suit: \" + card);\r\n      }\r\n    }\r\n  }\r\n```"}}
{"actor":{"display_login":"jaychang0917"}}