I want to create a string using the format, replacing some of the formatted markers with the properties from the bean. Is there a library that supports this, or will I have to create my own implementation?
Let me show you an example. Say I have a bean Person ;
public class Person { private String id; private String name; private String age;
I want to specify format strings, for example:
"{name} is {age} years old." "Person id {id} is called {name}."
and automatically fill the format placeholders with values from the bean, for example:
String format = "{name} is {age} old." Person p = new Person(1, "Fred", "32 years"); String formatted = doFormat(format, person);
I looked at MessageFormat , but that only allows me to pass numeric indices, not bean.
Qwerky
source share