import java.util.*;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import kr.inflearn.BookDTO;
public class Project01_A {
public static void main(String[] args) {
//Object(BookDTO) -> JSON(String)
BookDTO dto = new BookDTO("",21000,"",670);
Gson g = new Gson();
String json=g.toJson(dto);
System.out.println(json);//{"title":"","price":21000,"compony":"","page":670}
//JSON(String) ->Object(BookDTO)
BookDTO dto1=g.fromJson(json, BookDTO.class);
System.out.println(dto1); //BookDTO [title=, price=21000, compony=, page=670]
System.out.println(dto1.getTitle()+"\t"+dto1.getPrice());
//Object(List) -> JSON(String) : [{ }, { }....]
List lst=new ArrayList();
lst.add(new BookDTO("1",21000,"1",570));
lst.add(new BookDTO("2",31000,"2",670));
lst.add(new BookDTO("3",11000,"3",370));
String lstJson=g.toJson(lst);
System.out.println(lst);
System.out.println(lstJson);
//JSON(String) -> Object(List)
Listlst1=g.fromJson(lstJson, new TypeToken(){}.getType());
for(BookDTO vo: lst1) {
System.out.println(vo);
}
}
}