Example usage for com.google.gson JsonDeserializationContext deserialize

List of usage examples for com.google.gson JsonDeserializationContext deserialize

Introduction

In this page you can find the example usage for com.google.gson JsonDeserializationContext deserialize.

Prototype

public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;

Source Link

Document

Invokes default deserialization on the specified object.

Usage

From source file:org.openhab.binding.neeo.internal.models.NeeoDevicesDeserializer.java

License:Open Source License

@Nullable
@Override//from   w w w.j  a v  a2 s  .c  o m
public NeeoDevices deserialize(@Nullable JsonElement jsonElement, @Nullable Type type,
        @Nullable JsonDeserializationContext context) throws JsonParseException {
    Objects.requireNonNull(jsonElement, "jsonElement cannot be null");
    Objects.requireNonNull(context, "context cannot be null");

    if (jsonElement instanceof JsonObject) {
        final List<NeeoDevice> scenarios = new ArrayList<>();
        for (Map.Entry<String, JsonElement> entry : ((JsonObject) jsonElement).entrySet()) {
            final NeeoDevice device = context.deserialize(entry.getValue(), NeeoDevice.class);
            scenarios.add(device);
        }

        return new NeeoDevices(scenarios.toArray(new NeeoDevice[0]));
    }
    return null;
}

From source file:org.openhab.binding.neeo.internal.models.NeeoMacrosDeserializer.java

License:Open Source License

@Nullable
@Override//from  w  w w.  j ava 2 s  . c  o  m
public NeeoMacros deserialize(@Nullable JsonElement jsonElement, @Nullable Type type,
        @Nullable JsonDeserializationContext context) throws JsonParseException {
    Objects.requireNonNull(jsonElement, "jsonElement cannot be null");
    Objects.requireNonNull(context, "context cannot be null");

    if (jsonElement instanceof JsonObject) {
        final List<NeeoMacro> scenarios = new ArrayList<>();
        for (Map.Entry<String, JsonElement> entry : ((JsonObject) jsonElement).entrySet()) {
            final NeeoMacro macro = context.deserialize(entry.getValue(), NeeoMacro.class);
            scenarios.add(macro);
        }

        return new NeeoMacros(scenarios.toArray(new NeeoMacro[0]));
    }
    return null;
}

From source file:org.openhab.binding.neeo.internal.models.NeeoRecipesDeserializer.java

License:Open Source License

@Nullable
@Override/*  w w w  .j  a va  2 s .c  om*/
public NeeoRecipes deserialize(@Nullable JsonElement jsonElement, @Nullable Type type,
        @Nullable JsonDeserializationContext context) throws JsonParseException {
    Objects.requireNonNull(jsonElement, "jsonElement cannot be null");
    Objects.requireNonNull(context, "context cannot be null");

    if (jsonElement instanceof JsonObject) {
        final List<NeeoRecipe> recipes = new ArrayList<>();
        for (Map.Entry<String, JsonElement> entry : ((JsonObject) jsonElement).entrySet()) {
            final NeeoRecipe recipe = context.deserialize(entry.getValue(), NeeoRecipe.class);
            recipes.add(recipe);
        }

        return new NeeoRecipes(recipes.toArray(new NeeoRecipe[0]));
    }
    return null;
}

From source file:org.openhab.binding.neeo.internal.models.NeeoRoomsDeserializer.java

License:Open Source License

@Nullable
@Override//  ww  w. j  a va2 s.co  m
public NeeoRooms deserialize(@Nullable JsonElement jsonElement, @Nullable Type type,
        @Nullable JsonDeserializationContext context) throws JsonParseException {
    Objects.requireNonNull(jsonElement, "jsonElement cannot be null");
    Objects.requireNonNull(context, "context cannot be null");
    if (jsonElement instanceof JsonObject) {
        final List<NeeoRoom> recipes = new ArrayList<>();
        for (Map.Entry<String, JsonElement> entry : ((JsonObject) jsonElement).entrySet()) {
            final NeeoRoom room = context.deserialize(entry.getValue(), NeeoRoom.class);
            recipes.add(room);
        }

        return new NeeoRooms(recipes.toArray(new NeeoRoom[0]));
    }
    return null;
}

From source file:org.openhab.binding.neeo.internal.models.NeeoScenariosDeserializer.java

License:Open Source License

@Nullable
@Override/*from   w  w w . j  a  v a2  s  .c om*/
public NeeoScenarios deserialize(@Nullable JsonElement jsonElement, @Nullable Type jtype,
        @Nullable JsonDeserializationContext context) throws JsonParseException {
    Objects.requireNonNull(jsonElement, "jsonElement cannot be null");
    Objects.requireNonNull(context, "context cannot be null");
    if (jsonElement instanceof JsonObject) {
        final List<NeeoScenario> scenarios = new ArrayList<>();
        for (Map.Entry<String, JsonElement> entry : ((JsonObject) jsonElement).entrySet()) {
            final NeeoScenario scenario = context.deserialize(entry.getValue(), NeeoScenario.class);
            scenarios.add(scenario);
        }

        return new NeeoScenarios(scenarios.toArray(new NeeoScenario[0]));
    }
    return null;
}

From source file:org.openhab.binding.tado.internal.api.converter.OverlayTerminationConditionTemplateConverter.java

License:Open Source License

@Override
public OverlayTerminationConditionTemplate deserialize(JsonElement json, Type type,
        JsonDeserializationContext context) throws JsonParseException {

    OverlayTerminationConditionType terminationType = OverlayTerminationConditionType
            .valueOf(json.getAsJsonObject().get("type").getAsString());

    if (terminationType == OverlayTerminationConditionType.TIMER) {
        return context.deserialize(json, TimerTerminationConditionTemplate.class);
    }/*from ww w. j ava 2s  .  c om*/

    // no converter, otherwise stackoverflow
    return new GsonBuilder().create().fromJson(json, OverlayTerminationConditionTemplate.class);
}

From source file:org.openhab.binding.tado.internal.api.converter.TerminationConditionConverter.java

License:Open Source License

@Override
public OverlayTerminationCondition deserialize(JsonElement json, Type type, JsonDeserializationContext context)
        throws JsonParseException {

    OverlayTerminationConditionType terminationType = OverlayTerminationConditionType
            .valueOf(json.getAsJsonObject().get("type").getAsString());

    if (terminationType == OverlayTerminationConditionType.MANUAL) {
        return context.deserialize(json, ManualTerminationCondition.class);
    } else if (terminationType == OverlayTerminationConditionType.TADO_MODE) {
        return context.deserialize(json, TadoModeTerminationCondition.class);
    } else if (terminationType == OverlayTerminationConditionType.TIMER) {
        return context.deserialize(json, TimerTerminationCondition.class);
    }//  w  w w .  j a  va2s  .  c  o  m

    return null;
}

From source file:org.openhab.binding.tado.internal.api.converter.ZoneCapabilitiesConverter.java

License:Open Source License

@Override
public GenericZoneCapabilities deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
    TadoSystemType settingType = TadoSystemType.valueOf(json.getAsJsonObject().get("type").getAsString());

    if (settingType == TadoSystemType.HEATING) {
        return context.deserialize(json, HeatingCapabilities.class);
    } else if (settingType == TadoSystemType.AIR_CONDITIONING) {
        return context.deserialize(json, AirConditioningCapabilities.class);
    } else if (settingType == TadoSystemType.HOT_WATER) {
        return context.deserialize(json, HotWaterCapabilities.class);
    }/*from   w  ww  .  j av  a 2s . co m*/

    return null;
}

From source file:org.openhab.binding.tado.internal.api.converter.ZoneSettingConverter.java

License:Open Source License

@Override
public GenericZoneSetting deserialize(JsonElement json, Type type, JsonDeserializationContext context) {

    TadoSystemType settingType = TadoSystemType.valueOf(json.getAsJsonObject().get("type").getAsString());

    if (settingType == TadoSystemType.HEATING) {
        return context.deserialize(json, HeatingZoneSetting.class);
    } else if (settingType == TadoSystemType.HOT_WATER) {
        return context.deserialize(json, HotWaterZoneSetting.class);
    } else if (settingType == TadoSystemType.AIR_CONDITIONING) {
        return context.deserialize(json, CoolingZoneSetting.class);
    }/*  w  w  w. ja v a 2  s  . com*/

    return null;
}

From source file:org.openhab.binding.tankerkoenig.internal.serializer.CustomTankerkoenigDetailResultDeserializer.java

License:Open Source License

@Override
public TankerkoenigDetailResult deserialize(final JsonElement json, final Type typeOfT,
        final JsonDeserializationContext context) throws JsonParseException {

    final JsonObject jsonObject = json.getAsJsonObject();
    final Boolean isOK = jsonObject.get("ok").getAsBoolean();
    TankerkoenigDetailResult result = new TankerkoenigDetailResult();
    if (isOK) {/*from   w w  w.j a  va 2s.c  o m*/
        final JsonObject jsonStation = jsonObject.get("station").getAsJsonObject();
        final Boolean isWholeDay = jsonStation.get("wholeDay").getAsBoolean();
        final Double e10 = jsonStation.get("e10").getAsDouble();
        final Double e5 = jsonStation.get("e5").getAsDouble();
        final Double diesel = jsonStation.get("diesel").getAsDouble();
        final String stationID = jsonStation.get("id").getAsString();
        final LittleStation littleStation = new LittleStation();
        OpeningTime[] openingTime = context.deserialize(jsonStation.get("openingTimes"), OpeningTime[].class);

        littleStation.setE10(e10);
        littleStation.setE5(e5);
        littleStation.setDiesel(diesel);
        littleStation.setID(stationID);
        final OpeningTimes openingTimes = new OpeningTimes(stationID, isWholeDay, openingTime);
        result.setLittleStation(littleStation);
        result.setOk(isOK);
        result.setwholeDay(isWholeDay);
        result.setOpeningTimes(openingTimes);
    } else {
        final String message = jsonObject.get("message").getAsString();
        result.setOk(isOK);
        result.setMessage(message);
    }
    return result;
}