case ValueTypes.YANG_IDENTIFIER_TYPE:
writeYangInstanceIdentifierInternal((YangInstanceIdentifier) value);
break;
- case ValueTypes.NULL_TYPE :
+ case ValueTypes.EMPTY_TYPE:
break;
case ValueTypes.STRING_BYTES_TYPE:
final byte[] valueBytes = value.toString().getBytes(StandardCharsets.UTF_8);
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.dom.DOMSource;
import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
+import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
case ValueTypes.YANG_IDENTIFIER_TYPE :
return readYangInstanceIdentifierInternal();
+ case ValueTypes.EMPTY_TYPE:
+ // Leaf nodes no longer allow null values and thus we no longer emit null values. Previously, the "empty"
+ // yang type was represented as null so we translate an incoming null value to Empty. It was possible for
+ // a BI user to set a string leaf to null and we're rolling the dice here but the chances for that are
+ // very low. We'd have to know the yang type but, even if we did, we can't let a null value pass upstream
+ // so we'd have to drop the leaf which might cause other issues.
+ case ValueTypes.NULL_TYPE:
+ return Empty.getInstance();
+
default :
return null;
}
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
+import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
public static final byte BIG_INTEGER_TYPE = 10;
public static final byte BIG_DECIMAL_TYPE = 11;
public static final byte BINARY_TYPE = 12;
+ // Leaf nodes no longer allow null values. The "empty" type is now represented as
+ // org.opendaylight.yangtools.yang.common.Empty. This is kept for backwards compatibility.
+ @Deprecated
public static final byte NULL_TYPE = 13;
public static final byte STRING_BYTES_TYPE = 14;
+ public static final byte EMPTY_TYPE = 15;
private static final Map<Class<?>, Byte> TYPES;
b.put(BigInteger.class, BIG_INTEGER_TYPE);
b.put(BigDecimal.class, BIG_DECIMAL_TYPE);
b.put(byte[].class, BINARY_TYPE);
+ b.put(Empty.class, EMPTY_TYPE);
TYPES = b.build();
}
}
public static byte getSerializableType(Object node) {
- if (node == null) {
- return NULL_TYPE;
- }
+ Objects.requireNonNull(node);
final Byte type = TYPES.get(node.getClass());
if (type != null) {
import org.junit.Assert;
import org.junit.Test;
import org.opendaylight.controller.cluster.datastore.util.TestModel;
+import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
new NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME))
.withChild(entry1).withChild(entry2).build())
.withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[]{1, 2, 3, 4}))
+ .withChild(ImmutableNodes.leafNode(TestModel.EMPTY_QNAME, Empty.getInstance()))
.withChild(Builders.orderedMapBuilder()
.withNodeIdentifier(new NodeIdentifier(TestModel.ORDERED_LIST_QNAME))
.withChild(ImmutableNodes.mapEntry(TestModel.ORDERED_LIST_ENTRY_QNAME,
public static final QName CHOICE_QNAME = QName.create(TEST_QNAME, "choice");
public static final QName SHOE_QNAME = QName.create(TEST_QNAME, "shoe");
public static final QName ANY_XML_QNAME = QName.create(TEST_QNAME, "any");
+ public static final QName EMPTY_QNAME = QName.create(TEST_QNAME, "empty-leaf");
public static final QName INVALID_QNAME = QName.create(TEST_QNAME, "invalid");
private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
private static final String DATASTORE_AUG_YANG = "/odl-datastore-augmentation.yang";
anyxml any {
}
+
+ leaf empty-leaf {
+ type empty;
+ }
}
}