-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support JsonNaming and JsonProperty for BeanIntrospectionModule #7139
Conversation
Support for JsonNaming was missing (same for the `property-naming-strategy` config property), and support for JsonProperty was spotty. This implements support for both. Also removed some old code that special-cased the property names for `Resource`. Not needed anymore since #6254 Fixes #6904 Fixes #6665 Fixes #7129 Fixes micronaut-security/#946
if (clazz.isPresent()) { | ||
try { | ||
Constructor<?> emptyConstructor = clazz.get().getConstructor(); | ||
return (PropertyNamingStrategy) emptyConstructor.newInstance(); | ||
} catch (NoSuchMethodException ignored) { | ||
} catch (ReflectiveOperationException e) { | ||
throw new RuntimeException("Failed to construct configured PropertyNamingStrategy", e); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use InstantiationUtils.tryInstantiate
for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i want to distinguish between constructor failure (-> error) and no constructor being present (-> default behavior)
jackson-databind/src/main/java/io/micronaut/jackson/modules/BeanIntrospectionModule.java
Outdated
Show resolved
Hide resolved
the sonar failure is because the graal feature cant be tested |
...son-databind/src/test/groovy/io/micronaut/jackson/modules/BeanIntrospectionModuleSpec.groovy
Outdated
Show resolved
Hide resolved
...son-databind/src/test/groovy/io/micronaut/jackson/modules/BeanIntrospectionModuleSpec.groovy
Show resolved
Hide resolved
jackson-databind/src/main/java/io/micronaut/jackson/modules/BeanIntrospectionModule.java
Show resolved
Hide resolved
jackson-databind/src/main/java/io/micronaut/jackson/modules/BeanIntrospectionModule.java
Show resolved
Hide resolved
} catch (NoSuchMethodException ignored) { | ||
return mapperConfig.getPropertyNamingStrategy(); | ||
} catch (ReflectiveOperationException e) { | ||
throw new RuntimeException("Failed to construct configured PropertyNamingStrategy", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have addressed two sonar issues. The one remaning is that it is telling us to use a less generic exception.
SonarCloud Quality Gate failed. |
Support for JsonNaming was missing (same for the
property-naming-strategy
config property), and support for JsonProperty was spotty. This implements both.Also removed some old code that special-cased the property names for
Resource
. Not needed anymore since #6254Fixes #6904
Fixes #6665
Fixes #7129
Fixes micronaut-security/#946