From 7b623913d8a1279a949b51013ea6e2e6b8e57407 Mon Sep 17 00:00:00 2001 From: ValerioC Date: Mon, 13 Feb 2023 11:56:03 +0100 Subject: [PATCH] Aggiunto controllo in avvio chiamate rest per evitare che i terminali con android inferiore all'8.0 --- .../core/rest/RESTBuilder.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/RESTBuilder.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/RESTBuilder.java index 3def3811..2d1cbd57 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/RESTBuilder.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/RESTBuilder.java @@ -1,5 +1,7 @@ package it.integry.integrywmsnative.core.rest; +import android.os.Build; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -59,20 +61,14 @@ public class RESTBuilder { String endpoint = "http://" + host + ":" + port + "/" + (addEmsApi ? "ems-api/" : ""); - Gson gson = new GsonBuilder() - .setDateFormat("dd/MM/yyyy HH:mm:ss") - .registerTypeAdapter(LocalDate.class, new LocalDateDeserializer()) - .registerTypeAdapter(LocalDate.class, new LocalDateSerializer()) - .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer()) - .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()) - .excludeFieldsWithModifiers(Modifier.TRANSIENT) - .create(); - Retrofit retrofit = new Retrofit.Builder() - .addConverterFactory(GsonConverterFactory.create(gson)) - .baseUrl(endpoint) - .client(client) - .build(); + GsonBuilder builder = new GsonBuilder().setDateFormat("dd/MM/yyyy HH:mm:ss").excludeFieldsWithModifiers(Modifier.TRANSIENT); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + builder.registerTypeAdapter(LocalDate.class, new LocalDateDeserializer()).registerTypeAdapter(LocalDate.class, new LocalDateSerializer()).registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer()).registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()); + } + Gson gson = builder.create(); + + Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(gson)).baseUrl(endpoint).client(client).build(); return retrofit.create(service); }