]> git.basschouten.com Git - openhab-addons.git/blob
df7bbfec1c2699efacc80de8e5e94fbc0daca554
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.hueemulation.internal.dto.response;
14
15 import java.lang.reflect.Type;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 import com.google.gson.JsonElement;
21 import com.google.gson.JsonObject;
22 import com.google.gson.JsonSerializationContext;
23 import com.google.gson.JsonSerializer;
24
25 /**
26  * This object describes the right hand side of "success".
27  *
28  * @author David Graeff - Initial contribution
29  */
30 @NonNullByDefault
31 public class HueSuccessGeneric extends HueSuccessResponse {
32     public String message;
33     public transient String key;
34
35     public HueSuccessGeneric(@Nullable Object message, String key) {
36         this.message = message != null ? String.valueOf(message) : "";
37         this.key = key;
38     }
39
40     public static class Serializer implements JsonSerializer<HueSuccessGeneric> {
41         @NonNullByDefault({})
42         @Override
43         public JsonElement serialize(HueSuccessGeneric product, Type type, JsonSerializationContext jsc) {
44             JsonObject jObj = new JsonObject();
45             jObj.addProperty(product.key, product.message);
46             return jObj;
47         }
48     }
49
50     public boolean isValid() {
51         return !message.isEmpty();
52     }
53 }