Skip to content

Commit

Permalink
Fix converter regression
Browse files Browse the repository at this point in the history
Fixes #774
  • Loading branch information
pawelprazak committed Aug 8, 2022
1 parent 0a27012 commit b3fd8e7
Showing 1 changed file with 38 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,33 +396,45 @@ private Object tryConvertObjectInner(
// call setters for all arguments
var setters = processSetters(builderType, Function.identity());
argumentsMap.forEach((name, argument) -> {
if (!setters.containsKey(name)) {
throw new IllegalArgumentException(String.format(
"Expected type '%s' (annotated with '%s') to have a setter annotated with @%s(\"%s\")",
targetType.getTypeName(),
CustomType.class.getTypeName(),
CustomType.Setter.class.getTypeName(),
name
));
}
// validate null and @Nullable presence
if (argument == null
&& !(extractSetterParameter(setters.get(name)).isAnnotationPresent(Nullable.class))) {
log.debug(String.format(
"Expected type '%s' (annotated with '%s') to have a setter annotated with @%s(\"%s\"). " +
"Setter '%s' parameter named '%s' lacks @%s annotation, " +
"so the value is required, but there is no value to deserialize.",
targetType.getTypeName(),
CustomType.class.getTypeName(),
CustomType.Setter.class.getTypeName(),
name,
setters.get(name),
setters.get(name).getName(),
Nullable.class.getTypeName()
));
}
try {
if (!setters.containsKey(name)) {
throw new IllegalArgumentException(String.format(
"Expected type '%s' (annotated with '%s') to have a setter annotated with @%s(\"%s\")",
targetType.getTypeName(),
CustomType.class.getTypeName(),
CustomType.Setter.class.getTypeName(),
name
));
}
// validate null and @Nullable presence
if (argument == null
&& !(extractSetterParameter(setters.get(name)).isAnnotationPresent(Nullable.class))) {
log.debug(String.format(
"Expected type '%s' (annotated with '%s') to have a setter annotated with @%s(\"%s\"). " +
"Setter '%s' parameter named '%s' lacks @%s annotation, " +
"so the value is required, but there is no value to deserialize.",
targetType.getTypeName(),
CustomType.class.getTypeName(),
CustomType.Setter.class.getTypeName(),
name,
setters.get(name),
setters.get(name).getName(),
Nullable.class.getTypeName()
));
}
setters.get(name).invoke(builder, argument);
var convertedArgument = tryConvertObjectInner(
String.format("%s(%s)", targetType.getTypeName(), name),
argument,
TypeShape.extract(extractSetterParameter(setters.get(name)))
);
setters.get(name).invoke(builder, convertedArgument);
} catch (IllegalArgumentException e) {
throw new IllegalStateException(String.format(
"Error invoking setter '%s' (on '%s'), setter parameters: '%s', argument type: '%s'",
name, targetType.getTypeName(),
Arrays.toString(setters.get(name).getParameterTypes()),
argument == null ? "null" : argument.getClass()
), e);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException(String.format("Unexpected exception: %s", e.getMessage()), e);
}
Expand Down

0 comments on commit b3fd8e7

Please sign in to comment.