Merge "Fix checkListKey not checking actual/expected values"
[yangtools.git] / yang / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / JSONLeafrefCodec.java
1 /*
2  * Copyright (c) 2014 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.codec.gson;
9
10 import com.google.gson.stream.JsonWriter;
11 import java.io.IOException;
12 import org.opendaylight.yangtools.yang.data.api.codec.LeafrefCodec;
13
14 final class JSONLeafrefCodec implements JSONCodec<Object>, LeafrefCodec<String> {
15     @Override
16     public Object deserialize(final String input) {
17         return input;
18     }
19
20     @Override
21     public String serialize(final Object input) {
22         return String.valueOf(input);
23     }
24
25     @Override
26     public boolean needQuotes() {
27         return true;
28     }
29
30     /**
31      * Serialize specified value with specified JsonWriter.
32      *
33      * @param writer JsonWriter
34      * @param value
35      */
36     @Override
37     public void serializeToWriter(JsonWriter writer, Object value) throws IOException {
38         writer.value(serialize(value));
39     }
40 }