更新时间:2023-11-17 19:44:22
一种解决方案非常简单,可用于1级嵌套.在替代答案中可以找到一种更复杂的方法,该方法也可能允许对Maps进行更深层的嵌套.
One solution is quite simple and works for 1-level nesting. A more sophisticated approach can be found in the alternative answer which possibly also allows for deeper nesting of Maps.
代替使用接口作为类型参数,只需使用像TreeMap
Instead of using an interface as type parameter, simply use a concrete class like TreeMap
@Parameter
private Map<String, TreeMap> converters.
The reason is this check in MapConverter which fails for an interface but suceeds for a concrete class:
private static Class<?> findElementType( final Type[] typeArguments )
{
if ( null != typeArguments && typeArguments.length > 1
&& typeArguments[1] instanceof Class<?> )
{
return (Class<?>) typeArguments[1];
}
return Object.class;
}
As a side-note, an as it is also related to this answer for Maven > 3.3.x it also works to install a custom converter by subclassing BasicComponentConfigurator
and using it as a Plexus component. BasicComponentConfigurator
has the DefaultConverterLookup
as a protected member variable and is hence easily accessible for registering custom converters.