Specialize JSONCodec to JSONValueWriter
[yangtools.git] / codec / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / JSONCodec.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.data.util.codec.TypeAwareCodec;
14
15 /**
16  * A codec capable of performing normalized value conversion with a {@link JsonWriter}.
17  *
18  * @param <T> Normalized value type
19  */
20 public sealed interface JSONCodec<T> extends TypeAwareCodec<T, Void, JSONValueWriter>
21         permits AbstractJSONCodec, EmptyJSONCodec, IdentityrefJSONCodec, InstanceIdentifierJSONCodec, UnionJSONCodec {
22     /**
23      * {@inheritDoc}.
24      *
25      * @throws IOException if the write fails
26      */
27     @Override
28     void writeValue(JSONValueWriter ctx, T value) throws IOException;
29
30     /**
31      * {@inheritDoc}.
32      *
33      * @deprecated Use {@link #parseValue(String)} instead.
34      */
35     @Override
36     @Deprecated
37     default T parseValue(final Void ctx, final String str) {
38         return parseValue(str);
39     }
40
41     /**
42      * Parse a String representation into its native format.
43      *
44      * @param str String representation
45      * @return Value in native format
46      * @throws IllegalArgumentException if the value does not parse or pass type validation
47      */
48     T parseValue(String str);
49
50     /**
51      * Return the {@link JSONValue} representation of a native value.
52      *
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
56      */
57     @NonNull JSONValue unparseValue(T value);
58 }