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.opendaylight.yangtools.yang.data.util.codec.TypeAwareCodec;
15 * A codec capable of performing normalized value conversion with a {@link JsonWriter}.
17 * @param <T> Normalized value type
19 public sealed interface JSONCodec<T> extends TypeAwareCodec<T, Object, JsonWriter>
20 permits AbstractJSONCodec, EmptyJSONCodec, IdentityrefJSONCodec, NullJSONCodec, UnionJSONCodec,
21 // FIXME: rename this guy
22 JSONInstanceIdentifierCodec {
26 * @throws IOException if the write fails
27 * @deprecated Use {@link #writeValue(JSONValueWriter, Object)} instead.
30 @Deprecated(since = "13.0.3", forRemoval = true)
31 default void writeValue(final JsonWriter writer, final T value) throws IOException {
32 writeValue(new DefaultJSONValueWriter(writer), value);
36 * Serialize specified value with specified {@link JSONValueWriter}.
38 * @param ctx Write context
39 * @param value Value in native format
40 * @throws IOException if the write fails
42 void writeValue(JSONValueWriter ctx, T value) throws IOException;
47 * @deprecated Use {@link #parseValue(String)} instead.
51 default T parseValue(final Object ctx, final String str) {
52 return parseValue(str);
56 * Parse a String representation into its native format.
58 * @param str String representation
59 * @return Value in native format
60 * @throws IllegalArgumentException if the value does not parse or pass type validation
62 T parseValue(String str);