Do not support unions with complex types
[yangtools.git] / data / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / codec / EmptyStringCodec.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.impl.codec;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
12 import org.opendaylight.yangtools.yang.common.Empty;
13 import org.opendaylight.yangtools.yang.data.api.codec.EmptyCodec;
14 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
15
16 final class EmptyStringCodec extends TypeDefinitionAwareCodec<Empty, EmptyTypeDefinition>
17         implements EmptyCodec<String> {
18     static final EmptyStringCodec INSTANCE = new EmptyStringCodec();
19
20     private EmptyStringCodec() {
21         super(null, Empty.class);
22     }
23
24     @Override
25     protected Empty deserializeImpl(final String product) {
26         checkArgument(product.isEmpty(), "The value must be empty");
27         return Empty.value();
28     }
29
30     @Override
31     protected String serializeImpl(final Empty input) {
32         return "";
33     }
34 }