If an instance-identifier type is encountered within a union, we
end up going to TypeDefinitionAwareCodec, which is not equiped to
handle the complexities of XML-encoding instance identifiers. Make
sure we do perform a check to side-step this problem.
Change-Id: Ib5bc79a26808f4101ce182e092418a29e5b7bdc8
JIRA: YANGTOOLS-1108
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
} else if (value instanceof QName && isIdentityrefUnion(type)) {
// Ugly special-case form unions with identityrefs
return encode(writer, (QName) value, parent);
} else if (value instanceof QName && isIdentityrefUnion(type)) {
// Ugly special-case form unions with identityrefs
return encode(writer, (QName) value, parent);
+ } else if (value instanceof YangInstanceIdentifier && isInstanceIdentifierUnion(type)) {
+ return encodeInstanceIdentifier(writer, (YangInstanceIdentifier) value);
} else {
return serialize(type, value);
}
} else {
return serialize(type, value);
}
+ private boolean isInstanceIdentifierUnion(final TypeDefinition<?> type) {
+ if (type instanceof UnionTypeDefinition) {
+ for (TypeDefinition<?> subtype : ((UnionTypeDefinition) type).getTypes()) {
+ if (subtype instanceof InstanceIdentifierTypeDefinition || isInstanceIdentifierUnion(subtype)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
private static String serialize(final @NonNull TypeDefinition<?> type, final @NonNull Object value) {
final TypeDefinitionAwareCodec<Object, ?> codec = TypeDefinitionAwareCodec.from(type);
if (codec == null) {
private static String serialize(final @NonNull TypeDefinition<?> type, final @NonNull Object value) {
final TypeDefinitionAwareCodec<Object, ?> codec = TypeDefinitionAwareCodec.from(type);
if (codec == null) {