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.mielecloud.internal.webservice.api.json;
15 import java.util.Objects;
16 import java.util.Optional;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
21 import com.google.gson.Gson;
22 import com.google.gson.JsonSyntaxException;
25 * Immutable POJO representing an error message. Queried from the Miele REST API.
27 * @author Björn Lange - Initial contribution
30 public class ErrorMessage {
32 private String message;
35 * Creates a new {@link ErrorMessage} from the given Json text.
37 * @param json The Json text.
38 * @return The created {@link ErrorMessage}.
39 * @throws MieleSyntaxException if parsing the data from {@code json} fails.
41 public static ErrorMessage fromJson(String json) {
43 ErrorMessage errorMessage = new Gson().fromJson(json, ErrorMessage.class);
44 if (errorMessage == null) {
45 throw new MieleSyntaxException("Failed to parse Json.");
48 } catch (JsonSyntaxException e) {
49 throw new MieleSyntaxException("Failed to parse Json.", e);
53 public Optional<String> getMessage() {
54 return Optional.ofNullable(message);
58 public int hashCode() {
59 return Objects.hash(message);
63 public boolean equals(@Nullable Object obj) {
70 if (getClass() != obj.getClass()) {
73 ErrorMessage other = (ErrorMessage) obj;
74 return Objects.equals(message, other.message);