简单无法处理开箱即用的接口:
org.simpleframework.xml.core.InstantiationException: Cannot
instantiate interface com.bitplan.restmodelmanager.Package for
interface com.bitplan.restmodelmanager.Package at
org.simpleframework.xml.core.ObjectFactory.getInstance(ObjectFactory.java:68)
ObjectFactory 的源代码(见下文)似乎表明策略可以解析接口的类。恕我直言,这里可以使用 guice 注射器。对于这样的战略,什么是好的(可能存在的)解决方案?
/**
* This method will instantiate an object of the field type, or if
* the <code>Strategy</code> object can resolve a class from the
* XML element then this is used instead. If the resulting type is
* abstract or an interface then this method throws an exception.
*
* @param node this is the node to check for the override
*
* @return this returns an instance of the resulting type
*/
@Override
public Instance getInstance(InputNode node) throws Exception {
Value value = getOverride(node);
Class expect = getType();
if(value == null) {
if(!isInstantiable(expect)) {
throw new InstantiationException("Cannot instantiate %s for %s", expect, type);
}
return context.getInstance(expect);
}
return new ObjectInstance(context, value);
}