Recently came upon a case where I want up-front but configurable types (long story). Typically I do this
Type t = new TypeToken<ArrayList<Integer>>() {}.getType();
I would like to place that right hand side into my spring properties file and either issue a call similar to this:
Type t = env.getProperty("type-property");
Or use @ConfigurationProperties.
I typically work with @ConfigurationProperties, but the repo I'm in does not have it available. I could make the case to have dependencies pulled in if the first way simply isn't possible, but the path of least resistance is preferable.
I have tried some variations of the following property definition with angle brackets, parentheses, and square brackets --- none worked out.
type-property=java.util.ArrayList<java.lang.Integer>
I've had a hard time getting anything useful with the kinds of search terms you're forced to use with this problem. I found this related question, but didn't have luck translating it to non-xml configuration (I cannot do xml style in this project either). link: Create a Guava TypeToken in Spring xml config?
EDIT: Using the answer provided by @LppEdd, I used the following calls for de/serialization:
Type sampleType = new TypeToken<HashSet<ArrayList<Integer>>>() {}.getType();
// serialize via java.lang.reflect.Type.getTypeName()
String serializedType = sampleType.getTypeName();
// above string value is "java.util.HashSet<java.util.ArrayList<java.lang.Integer>>"
// deserialize via org.eclipse.jetty.util.TypeUtil.fromName(String name)
Type sampleTypeAgain = TypeUtil.fromName(serializedType);