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.russound.internal.rio.models;
15 import java.util.concurrent.atomic.AtomicReference;
17 import com.google.gson.Gson;
18 import com.google.gson.GsonBuilder;
19 import com.google.gson.reflect.TypeToken;
22 * Utility class for common GSON related items
24 * @author Tim Roberts - Initial contribution
26 public class GsonUtilities {
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)
31 * @return a non-null {@link Gson}
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());