Built in Type Adapters
suggest changeMoshi has built-in support for reading and writing Java’s core data types:
- Primitives (int, float, char…) and their boxed counterparts (Integer, Float, Character…).
- Arrays
- Collections
- Lists
- Sets
- Maps Strings Enums
It supports your model classes by writing them out field-by-field. In the example above Moshi uses these classes:
class BlackjackHand { public final Card hidden_card; public final List<Card> visible_cards; ... } class Card { public final char rank; public final Suit suit; ... } enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES; } to read and write this JSON: { "hidden_card": { "rank": "6", "suit": "SPADES" }, "visible_cards": [ { "rank": "4", "suit": "CLUBS" }, { "rank": "A", "suit": "HEARTS" } ] }
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents