2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.impl.codec;
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.data.api.codec.BooleanCodec;
13 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
16 * Do not use this class outside of yangtools, its presence does not fall into the API stability contract.
19 public final class BooleanStringCodec extends TypeDefinitionAwareCodec<Boolean, BooleanTypeDefinition>
20 implements BooleanCodec<String> {
21 private BooleanStringCodec(final BooleanTypeDefinition typeDef) {
22 super(Boolean.class, typeDef);
25 public static @NonNull BooleanStringCodec from(final BooleanTypeDefinition typeDef) {
26 return new BooleanStringCodec(typeDef);
30 protected Boolean deserializeImpl(final String product) {
31 return switch (product) {
32 case "true" -> Boolean.TRUE;
33 case "false" -> Boolean.FALSE;
34 default -> throw new IllegalArgumentException(
35 "Invalid value '" + product + "' for boolean type. Allowed values are 'true' and 'false'");
40 protected String serializeImpl(final Boolean input) {
41 return input.toString();