f03805a31210924e728414a1266cab2bd5045342
[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.opendaylight.yangtools.yang.data.util.codec.TypeAwareCodec;
13
14 /**
15  * A codec capable of performing normalized value conversion with a {@link JsonWriter}.
16  *
17  * @param <T> Normalized value type
18  */
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 {
23     /**
24      * {@inheritDoc}.
25      *
26      * @throws IOException if the write fails
27      */
28     @Override
29     void writeValue(JsonWriter ctx, T value) throws IOException;
30
31     /**
32      * {@inheritDoc}.
33      *
34      * @deprecated Use {@link #parseValue(String)} instead.
35      */
36     @Override
37     @Deprecated
38     default T parseValue(final Object ctx, final String str) {
39         return parseValue(str);
40     }
41
42     /**
43      * Parse a String representation into its native format.
44      *
45      * @param str String representation
46      * @return Value in native format
47      * @throws IllegalArgumentException if the value does not parse or pass type validation
48      */
49     T parseValue(String str);
50 }