Merge "Bug 9092: revert to org.json temporarily"
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / parser / IdentifierCodec.java
1 /*
2  * Copyright (c) 2016 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.restconf.parser;
9
10 import org.opendaylight.restconf.parser.builder.YangInstanceIdentifierDeserializer;
11 import org.opendaylight.restconf.parser.builder.YangInstanceIdentifierSerializer;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
13 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
14
15 /**
16  * Codec for identifier to serialize {@link YangInstanceIdentifier} to
17  * {@link String} and deserialize {@link String} to
18  * {@link YangInstanceIdentifier}.
19  *
20  */
21 public final class IdentifierCodec {
22
23     private IdentifierCodec() {
24         throw new UnsupportedOperationException("Util class.");
25     }
26
27     public static String serialize(final YangInstanceIdentifier data, final SchemaContext schemaContext) {
28         return YangInstanceIdentifierSerializer.create(schemaContext, data);
29     }
30
31     public static YangInstanceIdentifier deserialize(final String data, final SchemaContext schemaContext) {
32         if (data == null) {
33             return YangInstanceIdentifier.builder().build();
34         }
35         return YangInstanceIdentifier.create(YangInstanceIdentifierDeserializer.create(schemaContext, data));
36     }
37 }