Assuming the following data model:
public Test {
private List<String> userRoles;
...
}
When requiring to deserialize the object manually and having to instantiate an object for the userRole
, the following problems happen:
- Java reflection recognizes
List<String>
asList
when calling the.GetType()
method - When calling
.GetGenericType()
method, the actual type ofT
cannot be instantiated, as the method does not provide any function for that purpose. - Extracting the type from inside the
<>
and instantiating throughClass.fromClass(...)
may cause problems as the generic type maybe very complex, for examplePair<Pair<String,int>, Pair<String,int>>
Assuming that deserialization takes place inside of the class as follows:
public Test{
public void deserialize(String object){
Field[] fields = this.getClass().getDeclaredFields();
}
How can I instantiate an object for the userRoles
??
Aucun commentaire:
Enregistrer un commentaire