我似乎遇到了不区分大小写的问题。我有一个有两种方法的类,它们的名称只有在导致扫描程序出现问题的情况下才有所不同。
更具体地说,我有一个REST API的响应类:
public interface Job {
@CheckForNull
List<Job> getPredecessors();
@CheckForNull
String getPREDECESSORS();
}
这个类是在构建中自动生成的,它的目的是让两个不同的getter具有相似的名称,但具有不同的大写。
当swagger扫描我的课程时,我收到一个错误:
Caused by: java.lang.IllegalArgumentException: Conflicting getter definitions for property "predecessors": com.termalabs.ac.rest.Job#getPREDECESSORS(0 params) vs com.termalabs.ac.rest.Job#getPredecessors(0 params)
at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getGetter(POJOPropertyBuilder.java:244)
at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getAccessor(POJOPropertyBuilder.java:364)
at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getPrimaryMember(POJOPropertyBuilder.java:396)
at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:306)
at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:183)
at io.swagger.converter.ModelConverterContextImpl.resolve(ModelConverterContextImpl.java:100)
at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:234)
at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:183)
at io.swagger.converter.ModelConverterContextImpl.resolve(ModelConverterContextImpl.java:100)
at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:159)
at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:110)
at io.swagger.converter.ModelConverterContextImpl.resolveProperty(ModelConverterContextImpl.java:80)
at io.swagger.converter.ModelConverters.readAsProperty(ModelConverters.java:58)
at io.swagger.jaxrs.Reader.parseMethod(Reader.java:896)
at io.swagger.jaxrs.Reader.read(Reader.java:322)
at io.swagger.jaxrs.Reader.read(Reader.java:172)
at io.swagger.jaxrs.config.BeanConfig.scanAndRead(BeanConfig.java:242)
at io.swagger.jaxrs.config.BeanConfig.setScan(BeanConfig.java:221)
at com.termalabs.server.restapi.JawsSwaggerApplication.<init>(JawsSwaggerApplication.java:40)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:150)
... 18 more
显然杰克森不能处理两种不同的具有相同拼写但不同大小写的吸气剂。这对我来说很奇怪,因为java和Json都区分大小写。
我可以在jackson中找到一些对MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES的引用,但我无法弄清楚如何使用它。
有没有办法让我的服务扫描区分大小写?
谢谢,
迈克尔