import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.lang.reflect.WildcardType;
import java.time.Instant;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
if (schema instanceof LeafSchemaNode) {
final LeafSchemaNode leafSchema = (LeafSchemaNode) schema;
+ // FIXME: MDSAL-670: this is not right as we need to find a concrete type, but this may return
+ // Object.class
final Class<?> valueType = method.getReturnType();
final IllegalArgumentCodec<Object, Object> codec = getCodec(valueType, leafSchema.getType());
valueNode = LeafNodeCodecContext.of(leafSchema, codec, method.getName(), valueType,
valueType = (Class<?>) genericType;
} else if (genericType instanceof ParameterizedType) {
valueType = (Class<?>) ((ParameterizedType) genericType).getRawType();
+ } else if (genericType instanceof WildcardType) {
+ // FIXME: MDSAL-670: this is not right as we need to find a concrete type
+ valueType = Object.class;
} else {
throw new IllegalStateException("Unexpected return type " + genericType);
}
} else if (BindingReflections.isBindingClass(valueType)) {
return getCodecForBindingClass(valueType, instantiatedType);
}
+ // FIXME: MDSAL-670: this is right for most situations, but we must never return NOOP_CODEC for
+ // valueType=Object.class
return ValueTypeCodec.NOOP_CODEC;
}
--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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.mdsal.binding.dom.codec.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.mdsal668.norev.Foo;
+import org.opendaylight.yang.gen.v1.mdsal668.norev.FooBuilder;
+import org.opendaylight.yang.gen.v1.mdsal668.norev.bar.Bar;
+import org.opendaylight.yang.gen.v1.mdsal668.norev.bar.BarBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+
+public class Mdsal668Test extends AbstractBindingCodecTest {
+ private static final NodeIdentifier FOO = new NodeIdentifier(Foo.QNAME);
+ private static final InstanceIdentifier<Foo> FOO_IID = InstanceIdentifier.create(Foo.class);
+
+ @Test
+ public void testLeaflistLeafref() {
+ assertEquals(Builders.containerBuilder()
+ .withNodeIdentifier(FOO)
+ .withChild(Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(Bar.QNAME))
+ .withChild(Builders.leafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(Bar.QNAME))
+ .withChild(Builders.leafSetEntryBuilder()
+ // FIXME: MDSAL-670: these should get translated to YangInstanceIdentifier.create(FOO)
+ .withNodeIdentifier(new NodeWithValue<>(Bar.QNAME, FOO_IID))
+ .withValue(FOO_IID)
+ .build())
+ .build())
+ .build())
+ .build(), codecContext.toNormalizedNode(FOO_IID,
+ new FooBuilder().setBar(new BarBuilder().setBar(List.of(FOO_IID)).build()).build())
+ .getValue());
+ }
+}