1
resposta

Java OO Gsoon

Nao consigo usar o Gson, esta dando esse erro: Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/GsonBuilder at Principal.PrincipalComBusca.main

inclusive eu ja importei o jar etc...
podem me ajudar?
package Principal;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.Scanner;

import com.google.gson.Gson;


import modelo.TituloOmdb;

public class PrincipalComBusca {

    public static void main(String[] args) throws IOException, InterruptedException {

        Scanner sc = new Scanner(System.in);
        System.out.println("Digite o filme: ");
        String movie = sc.nextLine();

        String endereco = "http://www.omdbapi.com/?t=" + movie + "&apikey=727fc5af";

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder().uri(URI.create(endereco)).build();

        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());

         String json = response.body();
            System.out.println(json);

            Gson gson = new GsonBuilder();


            TituloOmdb meuTitulo = gson.fromJson(json, TituloOmdb.class);
            System.out.println(meuTitulo);

    }

}
1 resposta

Reuvan, tudo bem ?

Você precisaria instanciar:

 Gson gson = new Gson();

Inves de usar GsonBuilder