2 * Copyright (c) 2014 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.codec.gson;
10 import static java.util.Objects.requireNonNull;
12 import org.opendaylight.yangtools.yang.data.impl.codec.DataStringCodec;
13 import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
16 * Abstract base implementation of {@link JSONCodec}, which wraps a {@link TypeDefinitionAwareCodec}.
18 * @param <T> Deserialized object type
20 abstract class AbstractJSONCodec<T> implements JSONCodec<T> {
21 private final DataStringCodec<T> codec;
23 AbstractJSONCodec(final DataStringCodec<T> codec) {
24 this.codec = requireNonNull(codec);
28 public final Class<T> getDataType() {
29 return codec.getInputClass();
33 public final T parseValue(final Object ctx, final String str) {
34 return codec.deserialize(str);
37 final String serialize(final T input) {
38 return codec.serialize(input);