Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve BytecodeRecorderImpl error message #17317

Merged
merged 1 commit into from
May 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1311,26 +1311,33 @@ public void prepare(MethodContext context) {
continue;
}
Class propertyType = i.getPropertyType();
if (ctorParamIndex == null
&& i.getReadMethod().getReturnType() != i.getWriteMethod().getParameterTypes()[0]) {
if (relaxedValidation) {
//this is a weird situation where the reader and writer are different types
//we iterate and try and find a valid setter method for the type we have
//OpenAPI does some weird stuff like this

for (Method m : param.getClass().getMethods()) {
if (m.getName().equals(i.getWriteMethod().getName())) {
if (m.getParameterTypes().length > 0
&& m.getParameterTypes()[0].isAssignableFrom(param.getClass())) {
propertyType = m.getParameterTypes()[0];
break;
if (ctorParamIndex == null) {
Class<?> getterReturnType = i.getReadMethod().getReturnType();
Class<?> setterParameterType = i.getWriteMethod().getParameterTypes()[0];
if (getterReturnType != setterParameterType) {
if (relaxedValidation) {
//this is a weird situation where the reader and writer are different types
//we iterate and try and find a valid setter method for the type we have
//OpenAPI does some weird stuff like this

for (Method m : param.getClass().getMethods()) {
if (m.getName().equals(i.getWriteMethod().getName())) {
if (m.getParameterTypes().length > 0
&& m.getParameterTypes()[0].isAssignableFrom(param.getClass())) {
propertyType = m.getParameterTypes()[0];
break;
}
}
}

}
} else {
throw new RuntimeException("Cannot serialise field '" + i.getName() + "' on object '" + param
+ "' of type '" + param.getClass().getName()
+ "' as getter and setter are of different types. Getter type is '"
+ getterReturnType.getName() + "' while setter type is '"
+ setterParameterType.getName()
+ "'.");
}
} else {
throw new RuntimeException("Cannot serialise field " + i.getName() + " on object " + param
+ " as setter and getters were different types");
}
}
DeferredParameter val = loadObjectInstance(propertyValue, existing,
Expand Down