Merge branch 'automations-fix-1' into 'dev'
Fixed GSON serializations of triggers See merge request sa4-2020/the-sanmarinoes/backend!104
This commit is contained in:
commit
a7e26aee98
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