''java: package Gson does not exist''
É o erro
import com.google.gson.gson; import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse;
public class ConsultaCep {
public Endereço buscaEndereço(String cep){
URI endereço = URI.create("https://viacep.com.br/ws/" + cep + "/json/");
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(endereço)
.build();
HttpResponse<String> response = null;
try {
response = HttpClient
.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
} catch (IOException | InterruptedException e) {
throw new RuntimeException("Não consegui obter o endereço a partir desse CEP.");
}
return new Gson().fromJson(response.body(), Endereço.class);
}
}