use of com.squareup.moshi.Moshi in project MovieGuide by esoxjem.
the class FavoritesStore method setFavorite.
public void setFavorite(Movie movie) {
SharedPreferences.Editor editor = pref.edit();
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<Movie> jsonAdapter = moshi.adapter(Movie.class);
String movieJson = jsonAdapter.toJson(movie);
editor.putString(movie.getId(), movieJson);
editor.apply();
}
use of com.squareup.moshi.Moshi in project moshi by square.
the class RecoverFromTypeMismatch method run.
public void run() throws Exception {
String json = "[\"DIAMONDS\", \"STARS\", \"HEARTS\"]";
Moshi moshi = new Moshi.Builder().add(DefaultOnDataMismatchAdapter.newFactory(Suit.class, Suit.CLUBS)).build();
JsonAdapter<List<Suit>> jsonAdapter = moshi.adapter(Types.newParameterizedType(List.class, Suit.class));
List<Suit> suits = jsonAdapter.fromJson(json);
System.out.println(suits);
}
use of com.squareup.moshi.Moshi 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.Moshi in project moshi by square.
the class CustomFieldName method run.
public void run() throws Exception {
String json = "" + "{" + " \"username\": \"jesse\"," + " \"lucky number\": 32" + "}\n";
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<Player> jsonAdapter = moshi.adapter(Player.class);
Player player = jsonAdapter.fromJson(json);
System.out.println(player);
}
use of com.squareup.moshi.Moshi in project moshi by square.
the class CustomTypeAdapter method run.
public void run() throws Exception {
String json = "" + "{\n" + " \"hidden_card\": \"6S\",\n" + " \"visible_cards\": [\n" + " \"4C\",\n" + " \"AH\"\n" + " ]\n" + "}\n";
Moshi moshi = new Moshi.Builder().add(new CardAdapter()).build();
JsonAdapter<BlackjackHand> jsonAdapter = moshi.adapter(BlackjackHand.class);
BlackjackHand blackjackHand = jsonAdapter.fromJson(json);
System.out.println(blackjackHand);
}
Aggregations