rmannibucau commented on code in PR #91:
URL: https://github.com/apache/johnzon/pull/91#discussion_r863514532
##########
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:
Shouldnt it let most RuntimeException go to not break exception handling in
user code?
##########
johnzon-mapper/src/main/java/org/apache/johnzon/mapper/ExceptionMessages.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.johnzon.mapper;
+
+import javax.json.JsonValue;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import static javax.json.JsonValue.ValueType.ARRAY;
+import static javax.json.JsonValue.ValueType.FALSE;
+import static javax.json.JsonValue.ValueType.NUMBER;
+import static javax.json.JsonValue.ValueType.OBJECT;
+import static javax.json.JsonValue.ValueType.STRING;
+import static javax.json.JsonValue.ValueType.TRUE;
+
+public class ExceptionMessages {
Review Comment:
Final ;)
##########
johnzon-mapper/src/main/java/org/apache/johnzon/mapper/ExceptionMessages.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.johnzon.mapper;
+
+import javax.json.JsonValue;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import static javax.json.JsonValue.ValueType.ARRAY;
+import static javax.json.JsonValue.ValueType.FALSE;
+import static javax.json.JsonValue.ValueType.NUMBER;
+import static javax.json.JsonValue.ValueType.OBJECT;
+import static javax.json.JsonValue.ValueType.STRING;
+import static javax.json.JsonValue.ValueType.TRUE;
+
+public class ExceptionMessages {
+
+ private ExceptionMessages() {
+ }
+
+ public static String simpleName(final Type type) {
Review Comment:
Cant we use getTypeName instead to simplify 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]