Genson 的内部库代码导致了 ArrayIndexOutOfBoundsException,因为它试图索引一个我认为为空的数组。见下文。
我得到以下堆栈跟踪:
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at com.owlike.genson.reflect.BeanPropertyFactory$StandardFactory.createMutator(BeanPropertyFactory.java:115)
at com.owlike.genson.reflect.BeanPropertyFactory$CompositeFactory.createMutator(BeanPropertyFactory.java:87)
at com.owlike.genson.reflect.BaseBeanDescriptorProvider.provideMethodMutators(BaseBeanDescriptorProvider.java:232)
at com.owlike.genson.reflect.BaseBeanDescriptorProvider.provideBeanPropertyMutators(BaseBeanDescriptorProvider.java:119)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider.provide(AbstractBeanDescriptorProvider.java:98)
at com.owlike.genson.reflect.BeanDescriptorProvider$CompositeBeanDescriptorProvider.provide(BeanDescriptorProvider.java:60)
at com.owlike.genson.convert.BasicConvertersFactory.provide(BasicConvertersFactory.java:104)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:69)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:51)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:75)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:64)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:55)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:19)
at com.owlike.genson.Genson.provideConverter(Genson.java:148)
at com.owlike.genson.convert.DefaultConverters$CollectionConverterFactory.create(DefaultConverters.java:239)
at com.owlike.genson.convert.DefaultConverters$CollectionConverterFactory.create(DefaultConverters.java:231)
at com.owlike.genson.convert.BasicConvertersFactory.provide(BasicConvertersFactory.java:97)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:69)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:51)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:75)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:64)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:55)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:19)
at com.owlike.genson.Genson.provideConverter(Genson.java:148)
at com.owlike.genson.Genson.serialize(Genson.java:272)
at com.owlike.genson.ext.jaxrs.GensonJsonConverter.writeTo(GensonJsonConverter.java:85)
它是由 Genson 库中的以下方法引起的:
public PropertyMutator createMutator(String name, Method method, Type ofType, Genson genson) {
Type expandedType = TypeUtil.expandType(method.getGenericParameterTypes()[0], ofType);
return new PropertyMutator.MethodMutator(name, method, expandedType,
getRawClass(ofType));
}
它来自方法中的以下代码:method.getGenericParameterTypes()[0]。当我调试它说该方法是“错误”。它试图对 MyObject 具有以下方法的 List 进行操作(仅显示失败的方法):
@XmlElement(nillable=true)
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
如何解决此错误?金森为什么要这么做?