Bump upstreams for Silicon
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / utils / 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.nb.rfc8040.utils.parser;
9
10 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
11 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
12
13 /**
14  * Codec for identifier to serialize {@link YangInstanceIdentifier} to
15  * {@link String} and deserialize {@link String} to
16  * {@link YangInstanceIdentifier}.
17  *
18  */
19 public final class IdentifierCodec {
20
21     private IdentifierCodec() {
22         throw new UnsupportedOperationException("Util class.");
23     }
24
25     public static String serialize(final YangInstanceIdentifier data, final EffectiveModelContext schemaContext) {
26         return YangInstanceIdentifierSerializer.create(schemaContext, data);
27     }
28
29     public static YangInstanceIdentifier deserialize(final String data, final EffectiveModelContext schemaContext) {
30         if (data == null) {
31             return YangInstanceIdentifier.builder().build();
32         }
33         return YangInstanceIdentifier.create(YangInstanceIdentifierDeserializer.create(schemaContext, data));
34     }
35 }