]> git.basschouten.com Git - openhab-addons.git/blob
46aa24c718197f5f665145e7fb116b5cb1f20a44
[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.tplinksmarthome.internal.model;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 import com.google.gson.FieldNamingPolicy;
18 import com.google.gson.Gson;
19 import com.google.gson.GsonBuilder;
20 import com.google.gson.annotations.Expose;
21
22 /**
23  * Util class to create a {@link Gson} object.
24  *
25  * @author Hilbrand Bouwkamp - Initial contribution
26  */
27 @NonNullByDefault
28 public final class GsonUtil {
29
30     private GsonUtil() {
31         // Util class
32     }
33
34     /**
35      * Creates a new {@link Gson} object.
36      *
37      * @return new {@link Gson} object.
38      */
39     public static Gson createGson() {
40         return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
41     }
42
43     /**
44      * Creates a new {@link Gson} object that uses the {@link Expose} annotation..
45      *
46      * @return new {@link Gson} object.
47      */
48     public static Gson createGsonWithExpose() {
49         return new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
50                 .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
51     }
52 }