edited GSONConfig

This commit is contained in:
omenem 2020-05-08 17:50:59 +02:00
parent b72f527b0d
commit 628edfd76f

View file

@ -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<AutomationFastUpdateRequest.ConditionDTO>
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<Trigger<?>>)
(src, typeOfSrc, context) -> context.serialize((Object) src));
builder.registerTypeAdapter(
Condition.class,
(JsonSerializer<Condition<?>>)
(src, typeOfSrc, context) -> context.serialize((Object) src));
return builder;
}