BUG-7983: unify JSONCodec and XmlCodec methods
[yangtools.git] / yang / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / EmptyJSONCodec.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
9 package org.opendaylight.yangtools.yang.data.codec.gson;
10
11 import com.google.gson.stream.JsonWriter;
12 import java.io.IOException;
13
14 final class EmptyJSONCodec implements JSONCodec<Void> {
15
16     static final EmptyJSONCodec INSTANCE = new EmptyJSONCodec();
17
18     private EmptyJSONCodec() {
19
20     }
21
22     @Override
23     public Class<Void> getDataType() {
24         return Void.class;
25     }
26
27     @Override
28     public Void parseValue(final Object ctx, final String input) {
29         return null;
30     }
31
32     @Override
33     public void writeValue(final JsonWriter ctx, final Void value) throws IOException {
34         ctx.beginArray();
35         ctx.value((String) null);
36         ctx.endArray();
37     }
38 }