2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.util.codec;
10 import com.google.common.annotations.Beta;
13 * A codec, which knows what the native representation for a particular data type is. It knows how to convert a native
14 * value to and from string representation based on some additional input or output context.
16 * @author Robert Varga
18 * @param <T> Data value type
19 * @param <I> Input context type
20 * @param <O> Output context type
23 public interface TypeAwareCodec<T, I, O> {
25 * Return the data type class.
27 * @return Data type class
29 Class<T> getDataType();
32 * Parse a String representation into its native format.
34 * @param ctx Parse context
35 * @param str String representation
36 * @return Value in native format
37 * @throws IllegalArgumentException if the value does not parse or pass type validation
39 T parseValue(I ctx, String str);
42 * Serialize specified value with specified JsonWriter.
44 * @param ctx Write context
45 * @param value Value in native format
46 * @throws Exception if the write fails
48 void writeValue(O ctx, T value) throws Exception;