GSON Test

This commit is contained in:
Samuel Wolff 2023-12-18 09:25:08 +01:00
parent db26bca5a3
commit bf9c99672d
2 changed files with 10 additions and 2 deletions

View File

@ -5,6 +5,10 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.WatchEvent;
import Logik.Kind;
import com.google.gson.Gson;
/** /**
* noch nicht getestet * noch nicht getestet
@ -25,7 +29,7 @@ public class RestApiClient implements IRestAPI{
public static void main(String[] args){ public static void main(String[] args){
new RestApiClient().get("Kind", 2); new RestApiClient().get("Kind", 1);
} }
@ -45,9 +49,12 @@ public class RestApiClient implements IRestAPI{
// Send the request and get the response // Send the request and get the response
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString()); HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
Gson gson = new Gson();
Kind test = gson.fromJson(httpResponse.body(), Kind.class);
// Print the response status code and body // Print the response status code and body
System.out.println("Status Code: " + httpResponse.statusCode()); System.out.println("Status Code: " + httpResponse.statusCode());
System.out.println("Response Body: " + httpResponse.body()); System.out.println("Response Body: " + test.getName());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -2,6 +2,7 @@ module de.subway_surfers.vpr_app {
requires javafx.controls; requires javafx.controls;
requires javafx.fxml; requires javafx.fxml;
requires java.net.http; requires java.net.http;
requires com.google.gson;
opens de.subway_surfers.vpr_app to javafx.fxml; opens de.subway_surfers.vpr_app to javafx.fxml;