final NodeCodecContext<?> childContext = byMethod.get(method).get();
@SuppressWarnings("unchecked")
final Optional<NormalizedNode<?, ?>> domChild = domData.getChild(childContext.getDomPathArgument());
- if (domChild.isPresent()) {
- return childContext.deserializeObject(domChild.get());
- } else if (childContext instanceof LeafNodeCodecContext) {
- return ((LeafNodeCodecContext)childContext).defaultObject();
- } else {
- return null;
- }
+
+ // We do not want to use Optional.map() here because we do not want to invoke defaultObject() when we have
+ // normal value because defaultObject() may end up throwing an exception intentionally.
+ return domChild.isPresent() ? childContext.deserializeObject(domChild.get()) : childContext.defaultObject();
}
@SuppressWarnings("checkstyle:illegalCatch")