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.bsblan.internal.api;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.bsblan.internal.api.dto.BsbLanApiContentDTO;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import com.google.gson.Gson;
22 import com.google.gson.JsonSyntaxException;
25 * Utility class to create JSON content.
27 * @author Peter Schraffl - Initial contribution
30 public class BsbLanApiContentConverter {
31 private static final Logger LOGGER = LoggerFactory.getLogger(BsbLanApiContentConverter.class);
32 private static final Gson GSON = new Gson();
34 public static String toJson(BsbLanApiContentDTO request) {
35 return GSON.toJson(request);
38 public static <T> @Nullable T fromJson(String content, Class<T> resultType) {
40 T result = GSON.fromJson(content, resultType);
42 LOGGER.debug("result null after json parsing (response = {})", content);
45 } catch (JsonSyntaxException e) {
46 LOGGER.debug("Parsing JSON API response failed: {}", e.getMessage());