Home > Net >  Programmatically pluralize type name in Java/Spring
Programmatically pluralize type name in Java/Spring

Time:08-03

I have a fairly simple issue, but I couldn't find a solution googling it. I'm writing a library with Java/Spring and I need to be able to convert the names of types in the usual Java Bean ways: uncapitalized and (sometimes) plural.

Example: for a class called NorseDeity I must be able to get the String "norseDeity" and "norseDeities".

Is there any Spring or Apache Commons method to perform such a conversion?

I know Spring itself does it (because it automagically names different properties correctly), but I can't find how to reproduce it.

CodePudding user response:

Uncapitalizing a word is pretty trivial in Java, but deriving the plural form is pretty tricky stuff. Evo Inflector looks very promising, and even claims that it's used by Spring.

  • Related