]> git.basschouten.com Git - openhab-addons.git/blob
2d5cb331e46be50e42632f700443e628ac14b248
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.pilight.internal.serializers;
14
15 import java.io.IOException;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 import com.fasterxml.jackson.core.JsonGenerator;
21 import com.fasterxml.jackson.databind.JsonSerializer;
22 import com.fasterxml.jackson.databind.SerializerProvider;
23
24 /**
25  * Serializer to map boolean values to an integer (1 and 0).
26  *
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
30  */
31 @NonNullByDefault
32 public class BooleanToIntegerSerializer extends JsonSerializer<Boolean> {
33
34     @Override
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);
39         }
40     }
41 }