2 * Copyright 2017-2018 Gregory Moyer and contributors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openhab.binding.lametrictime.api.common.impl;
18 import org.openhab.binding.lametrictime.api.common.impl.typeadapters.ActionTypeAdapterFactory;
19 import org.openhab.binding.lametrictime.api.common.impl.typeadapters.ApplicationTypeAdapterFactory;
20 import org.openhab.binding.lametrictime.api.common.impl.typeadapters.UpdateActionTypeAdapterFactory;
21 import org.openhab.binding.lametrictime.api.common.impl.typeadapters.imported.JSR310TypeAdapters;
22 import org.openhab.binding.lametrictime.api.common.impl.typeadapters.imported.RuntimeTypeAdapterFactory;
23 import org.openhab.binding.lametrictime.api.local.model.BooleanParameter;
24 import org.openhab.binding.lametrictime.api.local.model.IntegerParameter;
25 import org.openhab.binding.lametrictime.api.local.model.Parameter;
26 import org.openhab.binding.lametrictime.api.local.model.StringParameter;
28 import com.google.gson.FieldNamingPolicy;
29 import com.google.gson.Gson;
30 import com.google.gson.GsonBuilder;
32 public class GsonGenerator
34 public static Gson create()
39 public static Gson create(boolean prettyPrint)
41 GsonBuilder builder = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
42 .registerTypeAdapterFactory(new ApplicationTypeAdapterFactory())
43 .registerTypeAdapterFactory(new ActionTypeAdapterFactory())
44 .registerTypeAdapterFactory(new UpdateActionTypeAdapterFactory())
45 .registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(Parameter.class,
47 .registerSubtype(BooleanParameter.class,
49 .registerSubtype(StringParameter.class,
51 .registerSubtype(IntegerParameter.class,
54 // add Java 8 Time API support
55 JSR310TypeAdapters.registerJSR310TypeAdapters(builder);
59 builder.setPrettyPrinting();
62 return builder.create();
66 private GsonGenerator() {}