Fix su serializzatore GSON

This commit is contained in:
Giuseppe Scorrano 2024-03-01 18:00:28 +01:00
parent 377950c978
commit a1b3517b07
3 changed files with 7 additions and 13 deletions

View File

@ -22,6 +22,7 @@ import javax.inject.Singleton;
import it.integry.integrywmsnative.core.CommonConst; import it.integry.integrywmsnative.core.CommonConst;
import it.integry.integrywmsnative.core.model.MtbColt; import it.integry.integrywmsnative.core.model.MtbColt;
import it.integry.integrywmsnative.core.rest.model.OrdineUscitaInevasoDTO; import it.integry.integrywmsnative.core.rest.model.OrdineUscitaInevasoDTO;
import it.integry.integrywmsnative.core.utility.UtilityGson;
@Singleton @Singleton
public class ColliDataRecoverService { public class ColliDataRecoverService {
@ -108,7 +109,7 @@ public class ColliDataRecoverService {
private void loadLocalFile() { private void loadLocalFile() {
InputStream inputStream; InputStream inputStream;
Gson gson = new Gson(); Gson gson = UtilityGson.createObject();
try { try {
inputStream = mApplicationContext.openFileInput(CommonConst.Files.RECOVER_COLLO_FILE); inputStream = mApplicationContext.openFileInput(CommonConst.Files.RECOVER_COLLO_FILE);
@ -130,7 +131,7 @@ public class ColliDataRecoverService {
private void updateLocalFile() { private void updateLocalFile() {
FileOutputStream outputStream; FileOutputStream outputStream;
Gson gson = new Gson(); Gson gson = UtilityGson.createObject();
String jsonText = gson.toJson(mtbColtsSessions); String jsonText = gson.toJson(mtbColtsSessions);
try { try {

View File

@ -40,7 +40,7 @@ public class EntityRESTConsumer extends _BaseRESTConsumer {
if (response.body() != null) { if (response.body() != null) {
if (response.body().getEsito() == EsitoType.OK) { if (response.body().getEsito() == EsitoType.OK) {
Gson gson = new Gson(); Gson gson = UtilityGson.createObject();
T object = gson.fromJson(response.body().getEntity(), type); T object = gson.fromJson(response.body().getEntity(), type);
callback.onSuccess(object); callback.onSuccess(object);
@ -133,7 +133,7 @@ public class EntityRESTConsumer extends _BaseRESTConsumer {
if (response.body() != null) { if (response.body() != null) {
if (response.body().getEsito() == EsitoType.OK) { if (response.body().getEsito() == EsitoType.OK) {
Gson gson = new Gson(); Gson gson = UtilityGson.createObject();
List<JsonObject> jsons = response.body().getEntityList(); List<JsonObject> jsons = response.body().getEntityList();
List<T> newList = new ArrayList<T>(); List<T> newList = new ArrayList<T>();

View File

@ -32,6 +32,7 @@ import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
import it.integry.integrywmsnative.core.rest.model.system.RegisterDeviceRequestDTO; import it.integry.integrywmsnative.core.rest.model.system.RegisterDeviceRequestDTO;
import it.integry.integrywmsnative.core.settings.SettingsManager; import it.integry.integrywmsnative.core.settings.SettingsManager;
import it.integry.integrywmsnative.core.utility.UtilityDate; import it.integry.integrywmsnative.core.utility.UtilityDate;
import it.integry.integrywmsnative.core.utility.UtilityGson;
import it.integry.integrywmsnative.core.utility.UtilityString; import it.integry.integrywmsnative.core.utility.UtilityString;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
@ -72,15 +73,7 @@ public class SystemRESTConsumer extends _BaseRESTConsumer {
@Override @Override
public void onResponse(Call<ServiceRESTResponse<Object>> call, Response<ServiceRESTResponse<Object>> response) { public void onResponse(Call<ServiceRESTResponse<Object>> call, Response<ServiceRESTResponse<Object>> response) {
analyzeAnswer(response, "ProcessSql", o -> { analyzeAnswer(response, "ProcessSql", o -> {
Gson gson = new GsonBuilder() Gson gson = UtilityGson.createObject();
.registerTypeAdapter(Date.class, (JsonDeserializer<?>) (json, typeOfT, context) -> {
try {
return UtilityDate.recognizeDate(json.getAsString());
} catch (Exception e) {
throw new JsonParseException(e);
}
})
.create();
String json = gson.toJson(o); String json = gson.toJson(o);