Remove RestCodec 56/100556/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 12 Apr 2022 16:04:06 +0000 (18:04 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 12 Apr 2022 16:08:46 +0000 (18:08 +0200)
Inline the final simple type handling into prepareValueByType(),
rendering RestCodec superfluous.

JIRA: NETCONF-871
Change-Id: Ie649e28d4333e3c57b49a3593c639474a0c930ad
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/codecs/RestCodec.java [deleted file]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java

diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/codecs/RestCodec.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/codecs/RestCodec.java
deleted file mode 100644 (file)
index 4d369df..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040.codecs;
-
-import org.opendaylight.restconf.common.util.RestUtil;
-import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-// FIXME: what is this class even trying to do?
-public final class RestCodec {
-    private static final Logger LOG = LoggerFactory.getLogger(RestCodec.class);
-
-    private RestCodec() {
-        // Hidden on purpose
-    }
-
-    public static Object deserialize(final EffectiveModelContext schemaContext, final TypeDefinition<?> typeDefinition,
-            final String input) {
-        final TypeDefinition<?> type = RestUtil.resolveBaseTypeFrom(typeDefinition);
-
-        try {
-            final TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> typeAwarecodec =
-                TypeDefinitionAwareCodec.from(type);
-            if (typeAwarecodec != null) {
-                return typeAwarecodec.deserialize(String.valueOf(input));
-            } else {
-                // FIXME: this should be a hard error
-                LOG.debug("Codec for type \"{}\" is not implemented yet.", type.getQName().getLocalName());
-                return null;
-            }
-        } catch (final ClassCastException e) {
-            // FIXME: remove this catch when everyone use codecs
-            // FIXME: this should be a hard error
-            LOG.error("ClassCastException was thrown when codec is invoked with parameter {}", input, e);
-            return null;
-        }
-    }
-}
\ No newline at end of file
index 054da8c23e6d61da8f4d4c9fc431c719d0828805..ca4c28db7b70f596ae552f8dd93f1619b13c40c1 100644 (file)
@@ -20,7 +20,6 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.util.RestUtil;
 import org.opendaylight.restconf.nb.rfc8040.ApiPath;
 import org.opendaylight.restconf.nb.rfc8040.ApiPath.ListInstance;
-import org.opendaylight.restconf.nb.rfc8040.codecs.RestCodec;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -30,6 +29,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
 import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -275,7 +275,8 @@ public final class YangInstanceIdentifierDeserializer {
                 return new StringModuleInstanceIdentifierCodec(schemaContext).deserialize(value);
             }
 
-            return RestCodec.deserialize(schemaContext, typedef, value);
+            return verifyNotNull(TypeDefinitionAwareCodec.from(typedef),
+                "Unhandled type %s decoding %s", typedef, value).deserialize(value);
         } catch (IllegalArgumentException e) {
             throw new RestconfDocumentedException("Invalid value '" + value + "' for " + schemaNode.getQName(),
                 ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE, e);