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.unifi.internal.api.util;
15 import java.lang.reflect.Type;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.unifi.internal.api.cache.UniFiControllerCache;
20 import org.openhab.binding.unifi.internal.api.dto.UniFiClient;
21 import org.openhab.binding.unifi.internal.api.dto.UniFiUnknownClient;
22 import org.openhab.binding.unifi.internal.api.dto.UniFiWiredClient;
23 import org.openhab.binding.unifi.internal.api.dto.UniFiWirelessClient;
25 import com.google.gson.InstanceCreator;
26 import com.google.gson.JsonSyntaxException;
29 * The {@link UniFiClientInstanceCreator} creates instances of {@link UniFiClient}s during the JSON unmarshalling of
30 * controller responses.
32 * @author Matthew Bowman - Initial contribution
35 public class UniFiClientInstanceCreator implements InstanceCreator<UniFiClient> {
37 private final UniFiControllerCache cache;
39 public UniFiClientInstanceCreator(final UniFiControllerCache cache) {
44 public UniFiClient createInstance(final @Nullable Type type) {
45 if (UniFiUnknownClient.class.equals(type)) {
46 return new UniFiUnknownClient(cache);
48 if (UniFiWirelessClient.class.equals(type)) {
49 return new UniFiWirelessClient(cache);
51 if (UniFiWiredClient.class.equals(type)) {
52 return new UniFiWiredClient(cache);
54 throw new JsonSyntaxException("Expected a UniFi Client type, but got " + type);