rmannibucau commented on code in PR #91:
URL: https://github.com/apache/johnzon/pull/91#discussion_r864511109


##########
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:
   @dblevins so you mean you didn't change the exception stacktrace at all? If 
so fine for me (indeed it includes `getCause()` ;)). It is indeed about 
setters+getters (`write`/`read`) but also `Adapter`/`Converter`s (`toValue`). 
Think we should limit our breaking change to subclass existing exception in our 
own codebase but not force users to change their specific exception handling. A 
quick option is to refine the try/catch block to only needed parts I guess and 
passthrough `RuntimeException` as this which should enable to handle the cases 
you want to catch without side effects and other changes.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to