dblevins commented on code in PR #91: URL: https://github.com/apache/johnzon/pull/91#discussion_r865355702
########## johnzon-mapper/src/main/java/org/apache/johnzon/mapper/MappingParserImpl.java: ########## @@ -399,36 +403,43 @@ private Object buildObject(final Type inType, final JsonObject object, final boo final JsonValue jsonValue = jsonEntry.getValue(); final JsonValue.ValueType valueType = jsonValue != null ? jsonValue.getValueType() : null; - if (JsonValue.class == value.paramType) { - value.writer.write(t, jsonValue); - continue; - } - if (jsonValue == null) { - continue; - } + try { + if (JsonValue.class == value.paramType) { + value.writer.write(t, jsonValue); + continue; + } + if (jsonValue == null) { + continue; + } - final AccessMode.Writer setterMethod = value.writer; - if (NULL == valueType) { // forced - setterMethod.write(t, null); - } else { - Object existingInstance = null; - if (config.isReadAttributeBeforeWrite()) { - final Mappings.Getter getter = classMapping.getters.get(jsonEntry.getKey()); - if (getter != null) { - try { - existingInstance = getter.reader.read(t); - } catch (final RuntimeException re) { - // backward compatibility + final AccessMode.Writer setterMethod = value.writer; + if (NULL == valueType) { // forced + setterMethod.write(t, null); + } else { + Object existingInstance = null; + if (config.isReadAttributeBeforeWrite()) { + final Mappings.Getter getter = classMapping.getters.get(jsonEntry.getKey()); + if (getter != null) { + try { + existingInstance = getter.reader.read(t); + } catch (final RuntimeException re) { + // backward compatibility + } } } + final Object convertedValue = toValue( + existingInstance, jsonValue, value.converter, value.itemConverter, + value.paramType, value.objectConverter, + isDedup() ? new JsonPointerTracker(jsonPointer, jsonEntry.getKey()) : null, inType); + if (convertedValue != null) { + setterMethod.write(t, convertedValue); + } } - final Object convertedValue = toValue( - existingInstance, jsonValue, value.converter, value.itemConverter, - value.paramType, value.objectConverter, - isDedup() ? new JsonPointerTracker(jsonPointer, jsonEntry.getKey()) : null, inType); - if (convertedValue != null) { - setterMethod.write(t, convertedValue); - } + } catch (SetterMappingException alreadyHandled) { + throw alreadyHandled; + } catch (Exception e) { Review Comment: I dug deeper as to how a user can find their own RuntimeException on a `mapper.readObject` call: - Thrown from a Converter: `catch (MapperException e) { e.getCause(); }` will return the RuntimeException - Thrown from a setter: `catch (MapperException e) { e.getCause().getCause(); }` will return the RuntimeException - Thrown from a constructor: `catch (IllegalStateException e) { e.getCause(); }` will return the RuntimeException With all the scenarios handled very differently, I'm not sure I see a clear path forward that doesn't involve some kind of change. It seems at the very least the third scenario should be fixed so that users can catch MapperException, bringing it in line with the other two. Beyond that, I'm not sure we want to make strict guarantees about what exception a user does or does not find when they call `getCause()` In concrete terms that would greatly reduce the kind of changes we can make to the internals. The most pragmatic perspective I can imagine is that we simply guarantee their exception will be in the `getCause()` chain and they can interate through it to find it, but should not expect it to be at a specific position. Thoughts? For visibility, I have till Friday, then it's a couple weeks before I can do more. We may need to break this into two goals; tweaks if any to get this PR in; possible longer-term changes. One very simple option could be we simply make the next release 1.3 instead of 1.2.19 and say, "it's different, deal with it" -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@johnzon.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org