]> git.basschouten.com Git - openhab-addons.git/blob
ae826d0d6d7c147f57a969a448f58d3229edbe89
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.binding.unifi.internal.api.util;
14
15 import java.lang.reflect.Type;
16 import java.util.Calendar;
17
18 import com.google.gson.JsonDeserializationContext;
19 import com.google.gson.JsonDeserializer;
20 import com.google.gson.JsonElement;
21
22 /**
23  * The {@link UniFiTimestampDeserializer} is an implementation of {@link JsonDeserializer} that deserializes timestamps
24  * returned in the JSON responses of the UniFi controller.
25  *
26  * @author Matthew Bowman - Initial contribution
27  */
28 public class UniFiTimestampDeserializer implements JsonDeserializer<Calendar> {
29
30     @Override
31     public Calendar deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
32         String text = json.getAsJsonPrimitive().getAsString();
33         long millis = Long.valueOf(text) * 1000;
34         Calendar cal = Calendar.getInstance();
35         cal.setTimeInMillis(millis);
36         return cal;
37     }
38 }