dblevins commented on code in PR #91:
URL: https://github.com/apache/johnzon/pull/91#discussion_r873205579
##########
johnzon-mapper/src/main/java/org/apache/johnzon/mapper/MappingParserImpl.java:
##########
@@ -399,36 +412,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) {
Review Comment:
If we change it to catch and not wrap MapperExcpetion, than we defeat the
goal of the PR as now we'll no longer get the additional context of what class,
field name, field type and json snippet involved. The MapperExcpetions that
happen downstream of this catch are accurate, but often don't provide enough
context to be very useful in practice. So we catch those exceptions and wrap
them to provide the class, field, field type, and json snippet. We don't,
however, want to do that recursively so we let exceptions of just this type go
by.
I did consider other means to collect that information and make it
available. My first instinct was as having an object to aggregate that kind of
state that we could pass everywhere. It occurred to me that all that
information was already in the java stack, being tracked exactly the way we
needed, we just needed to find the right place to catch and add that detail.
What I liked about that is this kind of tracking is really only useful for
exceptions, but if we took a tracking-object kind of approach we'd be paying
for it all the time, exception or not. I decided it was best not to let myself
over-engineer it and take advantage of what is already in the stack.
--
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]