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.pilight.internal.serializers;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
20 import com.fasterxml.jackson.core.JsonGenerator;
21 import com.fasterxml.jackson.databind.JsonSerializer;
22 import com.fasterxml.jackson.databind.SerializerProvider;
25 * Serializer to map boolean values to an integer (1 and 0).
27 * @author Jeroen Idserda - Initial contribution
28 * @author Stefan Röllin - Port to openHAB 2 pilight binding
29 * @author Niklas Dörfler - Port pilight binding to openHAB 3 + add device discovery
32 public class BooleanToIntegerSerializer extends JsonSerializer<Boolean> {
35 public void serialize(@Nullable Boolean bool, @Nullable JsonGenerator jsonGenerator,
36 @Nullable SerializerProvider serializerProvider) throws IOException {
37 if (bool != null && jsonGenerator != null) {
38 jsonGenerator.writeObject(bool ? 1 : 0);