-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Actuator is using different methods for serialization and deserialization #23410
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
Comments
Thanks for the report, but I'm not sure that I have understood the problem. The Actuator uses an |
Sorry for not clear explanation. I am not too familiar with Spring terminology. I have the following ObjectMapper configuration in my app
It is probably not perfect code but that is what I have. After doing this I found out that actuator Logger endpoint returns 'snake case' JSONs in GET requests but still require lower case camel notation in POST. I spent some time in debugger and found that somewhere deep inside Spring code it is using Map deserializer to extract request parameters. It is coming from
you can see that body is already presented as Map here, so further processing in ReflectiveOperationInvoker.resolveArguments can't resolve arguments if they are sent in snake case. |
This is Jackson's standard behaviour. It treats Map and POJO deserialisation differently and you have only configured its POJO deserialisation behaviour. If you want to customise the map key deserialisation, you'll have to configure Jackson with a custom key deserializer to convert the received snake_case into the required camelCase. You can do so with a @Bean
Module customKeyDeserializer() {
SimpleModule module = new SimpleModule();
module.addKeyDeserializer(String.class, new KeyDeserializer() {
@Override
public Object deserializeKey(String key, DeserializationContext ctxt) throws IOException {
StringBuilder result = new StringBuilder();
char previous = 0;
for (char c : key.toCharArray()) {
if (c != '_') {
result.append(previous == '_' ? Character.toUpperCase(c) : c);
}
previous = c;
}
return result.toString();
}
});
return module;
} |
See also #22950 for a somewhat similar problem with the serialisation of error responses and #20291 for providing an Actuator-specific I'm going to close this one. Generally speaking we don't recommend try to customise the form of the JSON that the actuator accepts and produces. That's not easy right now as the |
Yes, I configured it differently and I want them to be different. My complain is that actuator APIs are processed asymmetric: input is de-serialized through Map and output through POJO. |
Actuator APIs (Logger for example) are using
Map deserializer when JSON is received and ObjectMapper when it is send. Which causes mismatched messages.
In my case I want ObectMapper to be configured with snake case and keep Maps unchanged.
If I do this I have to use lower camel notation on my POST/PUT methods and snake case in GETs.
The text was updated successfully, but these errors were encountered: