public class GoogleBookResponse {
private List listaDeItens = new ArrayList<>();
@Override public String toString() { return "listaDeItens=" + listaDeItens; }
public List getListaDeItens() { return listaDeItens; }
public VolumeInfo getVolumeinfo() {
return new VolumeInfo();
}
}
public class Itens {
private VolumeInfo volumeInfo;
public void listaDeLivros(GoogleBookResponse googleBookResponse) {
if (googleBookResponse != null) {
List<Itens> listaDeItens = googleBookResponse.getListaDeItens();
for (Itens item : listaDeItens) {
this.volumeInfo = item.getVolumeInfo();
System.out.println("Title: " + volumeInfo.getTitle());
System.out.println("Authors: " + volumeInfo.getAuthors());
System.out.println("Publisher Date: " + volumeInfo.getPublisherDate());
System.out.println("------------------------");
}
}else {
System.out.println("Nenhuma informação em nossa biblioteca sobre esse livro");
}
}
}
public class VolumeInfo {
private String title; private List authors; private String publisherDate;
public VolumeInfo(String title, List authors, String publisherDate) { this.title = title; this.authors = authors; this.publisherDate = publisherDate; }
@Override public String toString() { return "title = " + title + ", authors=" + authors + ", publisherDate='" + publisherDate; }
public String getTitle() { return title; }
public List getAuthors() { return authors; }
public String getPublisherDate() { return publisherDate; }
}
public class Principal { public static void main(String[] args) throws IOException, InterruptedException {
Scanner leitura = new Scanner(System.in);
System.out.println("Digite o nome do livro: ");
var tituloLivro = leitura.nextLine();
String chave = "AIzaSyCX5L92HYujHpn-AyOl8DPPk_gqHbKcZFw";
String endereco = "https://www.googleapis.com/books/v1/volumes?q=" + tituloLivro
.replace(" ", "++++++") + "&key=" + chave;
// try {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(endereco))
.build();
HttpResponse<String> response = client
.send(request, HttpResponse.BodyHandlers.ofString());
String json = response.body();
System.out.println(json);
Gson gson = new GsonBuilder()
.setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.create();
GoogleBookResponse meuTitulo = gson.fromJson(json, GoogleBookResponse.class);
System.out.println(meuTitulo);
preciso de ajuda em como trazer os aspectos dessa api