Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON schema fails to render when a list of Enumerated types is introduced into the data model if spring.data.rest.enable-enum-translation=true [DATAREST-1326] #1685

Open
spring-projects-issues opened this issue Dec 20, 2018 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@spring-projects-issues
Copy link

Doug Busley opened DATAREST-1326 and commented

Taking the example from Restbucks, when a collection of elements is added to the Order class as such:

 

public class Order extends AbstractAggregateRoot {
private final Location location;
 private final LocalDateTime orderedDate;
 private Status status;
 @ElementCollection
 private List<Milk> milks;
// rest of class excluded for brevity 

 

A GET request to http://localhost:8080/profile/orders with an Accept header set to application/schema+json results in:

 

{ "cause": null, "message": "class org.springframework.data.rest.webmvc.json.JsonSchema$JsonSchemaProperty cannot be cast to class org.springframework.data.rest.webmvc.json.JsonSchema$EnumProperty (org.springframework.data.rest.webmvc.json.JsonSchema$JsonSchemaProperty and org.springframework.data.rest.webmvc.json.JsonSchema$EnumProperty are in unnamed module of loader 'app')" }

 

The issue is only present if spring.data.rest.enable-enum-translation=true

 

Stacktrace from logs:

java.lang.ClassCastException: class org.springframework.data.rest.webmvc.json.JsonSchema$JsonSchemaProperty cannot be cast to class org.springframework.data.rest.webmvc.json.JsonSchema$EnumProperty (org.springframework.data.rest.webmvc.json.JsonSchema$JsonSchemaProperty and org.springframework.data.rest.webmvc.json.JsonSchema$EnumProperty are in unnamed module of loader 'app')java.lang.ClassCastException: class org.springframework.data.rest.webmvc.json.JsonSchema$JsonSchemaProperty cannot be cast to class org.springframework.data.rest.webmvc.json.JsonSchema$EnumProperty (org.springframework.data.rest.webmvc.json.JsonSchema$JsonSchemaProperty and org.springframework.data.rest.webmvc.json.JsonSchema$EnumProperty are in unnamed module of loader 'app') at org.springframework.data.rest.webmvc.json.JacksonSerializers$EnumTranslatingSerializer.customize(JacksonSerializers.java:120) ~[spring-data-rest-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter$JsonSchemaPropertyRegistrar.register(PersistentEntityToJsonSchemaConverter.java:338) ~[spring-data-rest-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.lambda$null$2(PersistentEntityToJsonSchemaConverter.java:256) ~[spring-data-rest-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at java.base/java.util.Optional.ifPresent(Optional.java:183) ~[na:na] at org.springframework.data.util.Optionals.ifPresentOrElse(Optionals.java:208) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.lambda$getPropertiesFor$4(PersistentEntityToJsonSchemaConverter.java:236) ~[spring-data-rest-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at java.base/java.util.Optional.map(Optional.java:265) ~[na:na] at org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.getPropertiesFor(PersistentEntityToJsonSchemaConverter.java:171) ~[spring-data-rest-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.convert(PersistentEntityToJsonSchemaConverter.java:160) ~[spring-data-rest-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.convert(PersistentEntityToJsonSchemaConverter.java:146) ~[spring-data-rest-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.data.rest.webmvc.RepositorySchemaController.schema(RepositorySchemaController.java:65) ~[spring-data-rest-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:215) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:142) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:890) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.12.jar:9.0.12] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar:5.1.2.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.12.jar:9.0.12] at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na

 


Affects: 3.1.3 (Lovelace SR3)

Referenced from: pull request #375

@spring-projects-issues
Copy link
Author

Doug Busley commented

Hello! There is an open PR for this here: #375

 

I'm not sure if there is any more action required on my part to get this reviewed and merged. Please let me know. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants