Java Generic method and generic deserializer


import java.util.List;

public class Deserializer {

public static void main(String[] args) {

Book book1 = new Book(120000l, "Effective Java", "Josh Bloch");
String json = new Gson().toJson(book1);
System.out.println("Book JSON: " + json);
Book deserialize = deserialize(json, Book.class);
System.out.println("Book 2: " + deserialize);

List<Book> books =
List.of(new Book(1001l, "Java", "James Gosling"), new Book(1001l, "Groovy", "Venkat"));
String booksJson = new Gson().toJson(books);
System.out.println("Books: " + books);
List<Book> deserialize1 = deserialize(booksJson, List.class);
System.out.println("Books 2: " + deserialize1);

public static <T> T deserialize(String json, Class<T> clazz) {
Gson gson = new Gson();
return gson.fromJson(json, clazz);

static class Book {
private long isbn;
private String title;
private String author;

Book(long isbn, String title, String author) {
this.isbn = isbn;
this.title = title; = author;

public long getIsbn() {
return isbn;

public String getAuthor() {
return author;

public String getTitle() {
return title;

public String toString() {
return "Book{"
+ "isbn="
+ isbn
+ ", title='"
+ title
+ '\''
+ ", author='"
+ author
+ '\''
+ '}';


  1. Borgata Hotel Casino & Spa - Mapyro
    Discover cheap hotel deals for Borgata 부산광역 출장마사지 Hotel 안성 출장샵 Casino & Spa 포항 출장안마 in Atlantic City starting at $49. 창원 출장샵 Borgata Hotel Casino 제주 출장마사지 & Spa has 4 hotel rooms.

  2. Some slot machines have up to as} 20 free spins that might be be} re-trigger by hitting more scatter symbols while others 1xbet supply a flat extra spins quantity without re-trigger options. Gamers are not limited in titles when they need to play free slot machines. Below are well-liked free slots without downloading from well-liked developers similar to Aristocrat, IGT, Konami, and so forth.

  3. The on-line gambling market includes of revenue generated by remote gaming actions by the use of the internet utilizing desktop and mobile gadgets. The market includes gambling institutions creating on-line sports betting, casino, bingo, lotteries, and poker video games, amongst others. The biggest and most progressive on-line gambling states, like New Jersey, Pennsylvania, and Michigan offer a full vary of choices for on-line casino gambling, poker and legalized on-line sports betting. Other states have given the green light to fully-operational on-line sports betting websites, like New York, Connecticut and Illinois, whereas we anticipate actual cash on-line casinos to observe nicely with|swimsuit}. However, the 코인카지노 actual concern of school scholar gambling or specifically disordered gambling within this population does not appear prominently in the analysis literature from studies carried out outside North America or Australia presently. The present international analysis literature on disordered gambling has tended to not focus on to} faculty college students per se however rather on college-aged young adults (ages 18–26).


Post a Comment

Popular Posts