2 * Copyright (c) 2010-2024 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.solax.internal.connectivity.rawdata;
15 import java.util.Arrays;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.solax.internal.util.GsonSupplier;
21 import com.google.gson.Gson;
22 import com.google.gson.annotations.SerializedName;
25 * The {@link LocalConnectRawDataBean} collects the raw data and the specific implementation to return the parsed data.
26 * If there are differences between the inverters probably would be wise to split the parsing in seprate class(es)
28 * @author Konstantin Polihronov - Initial contribution
31 public class LocalConnectRawDataBean implements RawDataBean {
33 private @Nullable String sn;
34 private @Nullable String ver;
36 @SerializedName("Data")
37 private short @Nullable [] data;
38 @SerializedName("Information")
39 private String @Nullable [] information;
40 private @Nullable String rawData;
43 public String toString() {
44 return "LocalConnectRawDataBean [sn=" + sn + ", ver=" + ver + ", type=" + type + ", Information="
45 + Arrays.toString(information) + ", Data=" + Arrays.toString(data) + "]";
48 public @Nullable String getSn() {
52 public void setSn(@Nullable String sn) {
56 public @Nullable String getVer() {
60 public void setVer(@Nullable String ver) {
64 public int getType() {
68 public void setType(int type) {
72 public short @Nullable [] getData() {
76 public void setData(short @Nullable [] data) {
80 public String @Nullable [] getInformation() {
84 public void setInformation(String @Nullable [] information) {
85 this.information = information;
89 public @Nullable String getRawData() {
93 public void setRawData(String rawData) {
94 this.rawData = rawData;
97 public static LocalConnectRawDataBean fromJson(String json) {
99 throw new IllegalArgumentException("JSON payload should not be empty");
102 Gson gson = GsonSupplier.getInstance();
103 LocalConnectRawDataBean deserializedObject = gson.fromJson(json, LocalConnectRawDataBean.class);
104 if (deserializedObject == null) {
105 throw new IllegalStateException("Unexpected null result when deserializing JSON");
107 deserializedObject.setRawData(json);
108 return deserializedObject;