From 628edfd76f1cd97c0627edac1e76a35cb0ad0dd2 Mon Sep 17 00:00:00 2001 From: omenem Date: Fri, 8 May 2020 17:50:59 +0200 Subject: [PATCH] edited GSONConfig --- .../smarthut/config/GsonConfig.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonConfig.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonConfig.java index 4b69a07..d3c0c50 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonConfig.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonConfig.java @@ -1,6 +1,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.config; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationFastUpdateRequest; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Condition; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableState; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.State; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SwitchableState; @@ -43,12 +44,32 @@ public class GsonConfig { .registerSubtype( AutomationFastUpdateRequest.RangeTriggerDTO.class, "rangeTrigger"); + + RuntimeTypeAdapterFactory + runtimeTypeAdapterFactoryIII = + RuntimeTypeAdapterFactory.of( + AutomationFastUpdateRequest.ConditionDTO.class, "kind") + .registerSubtype( + AutomationFastUpdateRequest.BooleanConditionDTO.class, + "booleanCondition") + .registerSubtype( + AutomationFastUpdateRequest.RangeConditionDTO.class, + "rangeCondition") + .registerSubtype( + AutomationFastUpdateRequest.ThermostatConditionDTO.class, + "thermostatCondition"); + builder.registerTypeAdapterFactory(runtimeTypeAdapterFactory); builder.registerTypeAdapterFactory(runtimeTypeAdapterFactoryII); + builder.registerTypeAdapterFactory(runtimeTypeAdapterFactoryIII); builder.registerTypeAdapter( Trigger.class, (JsonSerializer>) (src, typeOfSrc, context) -> context.serialize((Object) src)); + builder.registerTypeAdapter( + Condition.class, + (JsonSerializer>) + (src, typeOfSrc, context) -> context.serialize((Object) src)); return builder; }