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 com.google.gson.stream.JsonWriter;
11 import java.io.IOException;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.data.util.codec.TypeAwareCodec;
16 * A codec capable of performing normalized value conversion with a {@link JsonWriter}.
18 * @param <T> Normalized value type
20 public sealed interface JSONCodec<T> extends TypeAwareCodec<T, Void, JSONValueWriter>
21 permits AbstractJSONCodec, EmptyJSONCodec, IdentityrefJSONCodec, InstanceIdentifierJSONCodec, UnionJSONCodec {
25 * @throws IOException if the write fails
28 void writeValue(JSONValueWriter ctx, T value) throws IOException;
33 * @deprecated Use {@link #parseValue(String)} instead.
37 default T parseValue(final Void ctx, final String str) {
38 return parseValue(str);
42 * Parse a String representation into its native format.
44 * @param str String representation
45 * @return Value in native format
46 * @throws IllegalArgumentException if the value does not parse or pass type validation
48 T parseValue(String str);
51 * Return the {@link JSONValue} representation of a native value.
53 * @param value Value in native format
54 * @return A {@link JSONValue}
55 * @throws IllegalArgumentException if the value does not parse or pass type validation
57 @NonNull JSONValue unparseValue(T value);