Fixed GSON serializations of triggers
This commit is contained in:
parent
74fee11814
commit
3d74e02434
1 changed files with 6 additions and 0 deletions
|
@ -4,6 +4,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationFastUpdateRequest;
|
|||
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;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Trigger;
|
||||
import com.google.gson.*;
|
||||
import java.lang.reflect.Type;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -27,6 +28,7 @@ public class GsonConfig {
|
|||
private static GsonBuilder configureBuilder() {
|
||||
final GsonBuilder builder = new GsonBuilder();
|
||||
builder.registerTypeAdapter(Json.class, new SpringfoxJsonToGsonAdapter());
|
||||
@SuppressWarnings({"rawTypes"})
|
||||
RuntimeTypeAdapterFactory<State> runtimeTypeAdapterFactory =
|
||||
RuntimeTypeAdapterFactory.of(State.class, "kind")
|
||||
.registerSubtype(SwitchableState.class, "switchableState")
|
||||
|
@ -43,6 +45,10 @@ public class GsonConfig {
|
|||
"rangeTrigger");
|
||||
builder.registerTypeAdapterFactory(runtimeTypeAdapterFactory);
|
||||
builder.registerTypeAdapterFactory(runtimeTypeAdapterFactoryII);
|
||||
builder.registerTypeAdapter(
|
||||
Trigger.class,
|
||||
(JsonSerializer<Trigger<?>>)
|
||||
(src, typeOfSrc, context) -> context.serialize((Object) src));
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue