]> git.basschouten.com Git - openhab-addons.git/blob
a0a694d5dea69596e67e5bdbd5852fff4dcfe1f2
[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.denonmarantz.internal.xml.adapters;
14
15 import javax.xml.bind.annotation.adapters.XmlAdapter;
16
17 /**
18  * Maps 'On' and 'Off' string values to a boolean
19  *
20  * @author Jeroen Idserda - Initial contribution
21  */
22 public class OnOffAdapter extends XmlAdapter<String, Boolean> {
23
24     @Override
25     public Boolean unmarshal(String v) throws Exception {
26         if (v != null) {
27             return Boolean.valueOf(v.toLowerCase().equals("on"));
28         }
29
30         return Boolean.FALSE;
31     }
32
33     @Override
34     public String marshal(Boolean v) throws Exception {
35         return v ? "On" : "Off";
36     }
37 }