cda1b4459c12322b5748b27c504b24f9fd84b30c
[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     private IdentifierCodec() {
21         // Hidden on purpose
22     }
23
24     public static String serialize(final YangInstanceIdentifier data, final EffectiveModelContext schemaContext) {
25         return YangInstanceIdentifierSerializer.create(schemaContext, data);
26     }
27
28     public static YangInstanceIdentifier deserialize(final String data, final EffectiveModelContext schemaContext) {
29         return data == null ? YangInstanceIdentifier.empty()
30             : YangInstanceIdentifier.create(YangInstanceIdentifierDeserializer.create(schemaContext, data));
31     }
32 }