use of com.squareup.moshi.recipes.models.Card in project moshi by square.
the class WriteJson method run.
public void run() throws Exception {
BlackjackHand blackjackHand = new BlackjackHand(new Card('6', SPADES), Arrays.asList(new Card('4', CLUBS), new Card('A', HEARTS)));
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<BlackjackHand> jsonAdapter = moshi.adapter(BlackjackHand.class);
String json = jsonAdapter.toJson(blackjackHand);
System.out.println(json);
}
use of com.squareup.moshi.recipes.models.Card in project moshi by square.
the class Unwrap method main.
public static void main(String[] args) throws Exception {
String json = "" + "{\"data\":" + " {\n" + " \"rank\": \"4\",\n" + " \"suit\": \"CLUBS\"\n" + " }" + "}";
Moshi moshi = new Moshi.Builder().add(EnvelopeJsonAdapter.FACTORY).build();
JsonAdapter<Card> adapter = moshi.adapter(Card.class, Enveloped.class);
Card out = adapter.fromJson(json);
System.out.println(out);
}
use of com.squareup.moshi.recipes.models.Card in project moshi by square.
the class ReadJsonList method run.
public void run() throws Exception {
String json = "" + "[\n" + " {\n" + " \"rank\": \"4\",\n" + " \"suit\": \"CLUBS\"\n" + " },\n" + " {\n" + " \"rank\": \"A\",\n" + " \"suit\": \"HEARTS\"\n" + " },\n" + " {\n" + " \"rank\": \"J\",\n" + " \"suit\": \"SPADES\"\n" + " }\n" + "]";
Moshi moshi = new Moshi.Builder().build();
Type listOfCardsType = Types.newParameterizedType(List.class, Card.class);
JsonAdapter<List<Card>> jsonAdapter = moshi.adapter(listOfCardsType);
List<Card> cards = jsonAdapter.fromJson(json);
System.out.println(cards);
}
Aggregations