BUG-6028: check value types for encapsulation
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / yangtools / binding / data / codec / impl / UnionValueOptionContext.java
index 52dd88e33d31d0f9b77c5ae5956847827509a6a9..06130fb824b773ab3ca53daecc3d5a6365bcefb5 100644 (file)
@@ -51,8 +51,12 @@ final class UnionValueOptionContext {
     }
 
     Object deserializeUnion(final Object input) {
-        final Object value;
+        // Side-step potential exceptions by checking the type if it is available
+        if (codec instanceof EncapsulatedValueCodec && !((EncapsulatedValueCodec) codec).canAcceptObject(input)) {
+            return null;
+        }
 
+        final Object value;
         try {
             value = codec.deserialize(input);
         } catch (Exception e) {