Built in Type Adapters
suggest changeMoshi has built-in support for reading and writing Java's core data types:
- Primitives (
int,float,char, and the rest) and their boxed counterparts (Integer,Float,Character, and the rest) - Arrays
- Collections
- Lists
- Sets
- Maps
- Strings
- Enums
It writes your model classes field by field. For the JSON below, 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;
}
{
"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