BUG-7983: unify JSONCodec and XmlCodec methods
[yangtools.git] / yang / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / NullJSONCodec.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 final class NullJSONCodec implements JSONCodec<Object> {
16     static final NullJSONCodec INSTANCE = new NullJSONCodec();
17     private static final Logger LOG = LoggerFactory.getLogger(NullJSONCodec.class);
18
19     private NullJSONCodec() {
20
21     }
22
23     @Override
24     public Class<Object> getDataType() {
25         return Object.class;
26     }
27
28     @Override
29     public Object parseValue(final Object ctx, final String str) {
30         LOG.warn("Call of the deserializeString method on null codec. No operation performed.");
31         return null;
32     }
33
34     @Override
35     public void writeValue(final JsonWriter ctx, final Object value) throws IOException {
36         // NOOP since codec is unknown.
37         LOG.warn("Call of the serializeToWriter method on null codec. No operation performed.");
38     }
39 }