]> git.basschouten.com Git - openhab-addons.git/blob
df3f50e3f97ac379ed572c85c1c7ed344e781f80
[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.binding.russound.internal.rio.models;
14
15 import java.util.concurrent.atomic.AtomicReference;
16
17 import com.google.gson.Gson;
18 import com.google.gson.GsonBuilder;
19 import com.google.gson.reflect.TypeToken;
20
21 /**
22  * Utility class for common GSON related items
23  *
24  * @author Tim Roberts - Initial contribution
25  */
26 public class GsonUtilities {
27     /**
28      * Utility method to create a standard {@link Gson} for the system. The standard GSon will register the
29      * {@link AtomicStringTypeAdapter} and the various serializers (Presets, Banks, Favorites)
30      *
31      * @return a non-null {@link Gson}
32      */
33     public static Gson createGson() {
34         final GsonBuilder gs = new GsonBuilder();
35         gs.registerTypeAdapter(new TypeToken<AtomicReference<String>>() {
36         }.getType(), new AtomicStringTypeAdapter());
37         gs.registerTypeAdapter(RioPreset.class, new RioPresetSerializer());
38         gs.registerTypeAdapter(RioBank.class, new RioBankSerializer());
39         gs.registerTypeAdapter(RioFavorite.class, new RioFavoriteSerializer());
40         return gs.create();
41     }
42 }