Let's assume I have the following class:
public class Sample<T> {
private String smth;
}
I need to have the name of the "smth" property depends on the generic type. For example: Sample<String>
should be turned to {"string":value}
and Sample<Integer>
to {"int":value}
I tried to use Jackson MixIn but it can be applied only on the concrete class (not generic)
Can anyone propose somethig to sort it out?
答案 0 :(得分:2)
此问题称为删除。
如果您有此代码
Sample<String> mysample = ...
并希望转换{"string":value}
这是不可能的。
在运行时,&lt;字符串&gt; 信息不可用。这称为擦除。