question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose `translate()` method of standard `PropertyNamingStrategy` implementations

See original GitHub issue

Is your feature request related to a problem? Please describe.

I work on a REST server that uses PropertyNamingStrategies.SNAKE_CASE to translate Java property names to JSON field names. The application code needs to report errors to the REST client, using the translated property names, but it has only the Java names. PropertyNamingStrategies.SNAKE_CASE does have a translate function that does exactly what I need, but it is declared in NamingBase while SNAKE_CASE is declaredas PropertyNamingStrategy.

Describe the solution you’d like

  • Declare public translate(String) in PropertyNamingStrategy, or
  • Declare PropertyNamingStrategy SNAKE_CASE as NamingBase or SnakeCaseStrategy.

Usage example

Current application code:

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
...
private static SnakeCaseStrategy toSnakeCaseConverter = new SnakeCaseStrategy();
...
propertyName = toSnakeCaseConverter.translate(propertyName);

Application code after change:

import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SNAKE_CASE;
...
propertyName = toSnakeCaseConverter.translate(propertyName);

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
toolforgercommented, Oct 23, 2022

I should be able to check on Monday. Code review already happened, nothing I could see.

0reactions
cowtowncodercommented, Oct 23, 2022

Yup, no auto-formatter. I tend to end up fighting more wrt indentation and never get it quite right. As to static final vs final static I forget which one is the canonical one which ends up being one or the other; compilers accept either so to me it does not greatly matter. Just should be same within single class file.

Anyway, please LMK if somehow something was missing; otherwise I assume this works like it should 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

PropertyNamingStrategy (jackson-databind 2.7.0 API)
Class that defines how names of JSON properties ("external names") are derived from names of POJO methods and fields ("internal names"), in cases...
Read more >
PropertyNamingStrategy (The Adobe AEM Quickstart and Web ...
Default (empty) implementation returns suggested ("default") name unmodified. Note that the strategy is guaranteed to be called once per logical property ...
Read more >
SpringBoot 配置文件application.properties - wade&luffy - 博客园
expose -session-attributes=false # Set whether all HttpSession attributes should be added to the model prior to merging with the template. spring ...
Read more >
Index (jackson-databind 2.9.10.1 API) - Javadoc.io
actualType() - Method in class com.fasterxml.jackson.databind.type. ... Standard implementation used by ObjectMapper : adds methods only exposed to ...
Read more >
Spring Boot Reference Guide
Exposing YAML as properties in the Spring Environment; 23.6.3. ... You can use Spring Boot in the same way as any standard Java...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found