2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.freeboxos.internal.api.deserialization;
15 import java.lang.reflect.Type;
16 import java.util.Objects;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.freeboxos.internal.api.rest.PlayerManager.ForegroundApp;
21 import org.openhab.binding.freeboxos.internal.api.rest.PlayerManager.PlayerContext;
22 import org.openhab.binding.freeboxos.internal.api.rest.PlayerManager.TvContext;
24 import com.google.gson.JsonDeserializationContext;
25 import com.google.gson.JsonDeserializer;
26 import com.google.gson.JsonElement;
27 import com.google.gson.JsonParseException;
30 * Custom deserializer to handle {@link ForegroundApp} object
32 * @author Gaƫl L'hopital - Initial contribution
35 public class ForegroundAppDeserializer implements JsonDeserializer<ForegroundApp> {
38 public @NonNull ForegroundApp deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
39 throws JsonParseException {
42 String thePackage = json.getAsJsonObject().get("package").getAsString();
43 JsonElement jsonElement2 = json.getAsJsonObject().get("context");
44 if (jsonElement2 == null) {
46 } else if ("fr.freebox.tv".equals(thePackage)) {
47 obj = context.deserialize(jsonElement2, TvContext.class);
49 obj = context.deserialize(jsonElement2, PlayerContext.class);
52 int packageId = json.getAsJsonObject().get("package_id").getAsInt();
53 String curlUrl = json.getAsJsonObject().get("cur_url").getAsString();
54 Objects.requireNonNull(thePackage);
55 return new ForegroundApp(packageId, curlUrl, obj, thePackage);