katharsis-framework icon indicating copy to clipboard operation
katharsis-framework copied to clipboard

Resource of class not found: java.lang.Class When traversing some links

Open taylormathewson opened this issue 7 years ago • 9 comments

When trying to traverse relationships where the target entity has a @JsonApiResource annotation, I get an exception of Resource of class not found: java.lang.Class

The code issue is fairly apparent. In io.katharsis.core.internal.registry. ResourceRegistryImpl.getEntry(T targetDataObject) has the following code:

	public <T> RegistryEntry getEntry(T targetDataObject) {
		Class<?> targetDataObjClass = targetDataObject.getClass();
		RegistryEntry relationshipEntry;
		if (targetDataObjClass.getAnnotation(JsonApiResource.class) != null) {
			relationshipEntry = findEntry(targetDataObjClass.getAnnotation(JsonApiResource.class).type(), targetDataObjClass.getClass());
		} else {
			relationshipEntry = findEntry(targetDataObject.getClass());
		}
		return relationshipEntry;
	}

the block of the if condition always gets the class of a class, which will always be java.lang.Class. This call should just use the variable.

Explicitly, I believe:

relationshipEntry = findEntry(targetDataObjClass.getAnnotation(JsonApiResource.class).type(), targetDataObjClass.getClass());

should be:

relationshipEntry = findEntry(targetDataObjClass.getAnnotation(JsonApiResource.class).type(), targetDataObjClass);

(Change is at rightmost side)

Full Stack:

io.katharsis.invoker.KatharsisInvokerException: com.fasterxml.jackson.databind.JsonMappingException: Resource of class not found: java.lang.Class (through reference chain: java.util.ArrayList[1]) at io.katharsis.spring.KatharsisFilterV2.invoke(KatharsisFilterV2.java:104) ~[katharsis-spring-2.8.2.jar:na] at io.katharsis.spring.KatharsisFilterV2.doFilter(KatharsisFilterV2.java:87) ~[katharsis-spring-2.8.2.jar:na] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1699) ~[jetty-servlet-9.3.14.v20161028.jar:9.3.14.v20161028] at io.katharsis.spring.ErrorHandlerFilter.doFilterInternal(ErrorHandlerFilter.java:38) ~[katharsis-spring-2.8.2.jar:na] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1699) ~[jetty-servlet-9.3.14.v20161028.jar:9.3.14.v20161028] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1699) ~[jetty-servlet-9.3.14.v20161028.jar:9.3.14.v20161028] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1699) ~[jetty-servlet-9.3.14.v20161028.jar:9.3.14.v20161028] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1699) ~[jetty-servlet-9.3.14.v20161028.jar:9.3.14.v20161028] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1699) ~[jetty-servlet-9.3.14.v20161028.jar:9.3.14.v20161028] at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:107) ~[spring-boot-actuator-1.4.2.RELEASE.jar:1.4.2.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1699) ~[jetty-servlet-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582) [jetty-servlet-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) [jetty-security-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226) [jetty-server-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180) [jetty-server-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512) [jetty-servlet-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-server-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112) [jetty-server-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134) [jetty-server-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.server.Server.handle(Server.java:534) [jetty-server-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320) [jetty-server-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251) [jetty-server-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273) [jetty-io-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95) [jetty-io-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93) [jetty-io-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303) [jetty-util-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148) [jetty-util-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136) [jetty-util-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671) [jetty-util-9.3.14.v20161028.jar:9.3.14.v20161028] at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589) [jetty-util-9.3.14.v20161028.jar:9.3.14.v20161028] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111] Caused by: com.fasterxml.jackson.databind.JsonMappingException: Resource of class not found: java.lang.Class (through reference chain: java.util.ArrayList[1]) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:303) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:2493) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.core.base.GeneratorBase.writeObject(GeneratorBase.java:378) ~[jackson-core-2.8.4.jar:2.8.4] at com.fasterxml.jackson.core.JsonGenerator.writeObjectField(JsonGenerator.java:1662) ~[jackson-core-2.8.4.jar:2.8.4] at io.katharsis.jackson.serializer.DataLinksContainerSerializer.serialize(DataLinksContainerSerializer.java:35) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.DataLinksContainerSerializer.serialize(DataLinksContainerSerializer.java:23) ~[katharsis-core-2.8.2.jar:na] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:2493) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.core.base.GeneratorBase.writeObject(GeneratorBase.java:378) ~[jackson-core-2.8.4.jar:2.8.4] at com.fasterxml.jackson.core.JsonGenerator.writeObjectField(JsonGenerator.java:1662) ~[jackson-core-2.8.4.jar:2.8.4] at io.katharsis.jackson.serializer.ContainerSerializer.writeRelationshipFields(ContainerSerializer.java:262) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.ContainerSerializer.writeData(ContainerSerializer.java:119) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.ContainerSerializer.serialize(ContainerSerializer.java:86) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.ContainerSerializer.serialize(ContainerSerializer.java:41) ~[katharsis-core-2.8.2.jar:na] at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:119) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:79) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:18) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:2493) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.core.base.GeneratorBase.writeObject(GeneratorBase.java:378) ~[jackson-core-2.8.4.jar:2.8.4] at com.fasterxml.jackson.core.JsonGenerator.writeObjectField(JsonGenerator.java:1662) ~[jackson-core-2.8.4.jar:2.8.4] at io.katharsis.jackson.serializer.BaseResponseSerializer.serializeResourceCollection(BaseResponseSerializer.java:125) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.BaseResponseSerializer.writeResponseWithResources(BaseResponseSerializer.java:88) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.BaseResponseSerializer.serialize(BaseResponseSerializer.java:50) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.BaseResponseSerializer.serialize(BaseResponseSerializer.java:27) ~[katharsis-core-2.8.2.jar:na] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3681) ~[jackson-databind-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3014) ~[jackson-databind-2.8.4.jar:2.8.4] at io.katharsis.spring.KatharsisFilterV2.dispatchRequest(KatharsisFilterV2.java:149) ~[katharsis-spring-2.8.2.jar:na] at io.katharsis.spring.KatharsisFilterV2.invoke(KatharsisFilterV2.java:102) ~[katharsis-spring-2.8.2.jar:na] ... 42 common frames omitted Caused by: io.katharsis.resource.exception.init.ResourceNotFoundInitializationException: Resource of class not found: java.lang.Class at io.katharsis.resource.registry.ResourceRegistry.getEntry(ResourceRegistry.java:103) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.resource.registry.ResourceRegistry.getEntry(ResourceRegistry.java:77) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.resource.registry.ResourceRegistry.getEntry(ResourceRegistry.java:111) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.RelationshipContainerSerializer.writeToOneLinkage(RelationshipContainerSerializer.java:126) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.RelationshipContainerSerializer.writeLinkageField(RelationshipContainerSerializer.java:94) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.RelationshipContainerSerializer.writeLinkage(RelationshipContainerSerializer.java:85) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.RelationshipContainerSerializer.serialize(RelationshipContainerSerializer.java:45) ~[katharsis-core-2.8.2.jar:na] at io.katharsis.jackson.serializer.RelationshipContainerSerializer.serialize(RelationshipContainerSerializer.java:24) ~[katharsis-core-2.8.2.jar:na] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292) ~[jackson-databind-2.8.4.jar:2.8.4] ... 71 common frames omitted

taylormathewson avatar Mar 03 '17 16:03 taylormathewson

If you create a PR from master we can have a quick review and get it merged in. Thanks for identifying this and helping. If/when you make the PR please reference this issue

chb0github avatar Mar 06 '17 21:03 chb0github

Any update in here @chb0github @Ramblurr? I think this should be fixed in next release.

masterspambot avatar Mar 20 '17 19:03 masterspambot

This does look like an obvious bug. But I'm not sure how it is being triggered. Could @taylormathewson provide a test case or even just an example query of how to trigger it?

Ramblurr avatar Mar 21 '17 09:03 Ramblurr

So I'm using spring boot, katharsis-spring and katharsis-jpa. katharsis version is 2.8.2, spring boot version is 1.4.2 I've got an object (hypothetically Car) which aggregates some other objects (hypothetically Car has Wheels in a list). If I annotate the aggregated objects (Wheel) with @JsonApiResource, this fails and throws the exception. Sorry I can't be more explicit, hope this helps. I will try to provide a test case later today, but am a bit swamped.

taylormathewson avatar Mar 21 '17 13:03 taylormathewson

What is the hypothetical URL/get request you're making that causes the exception?

Ramblurr avatar Mar 21 '17 13:03 Ramblurr

Please take our example project and either give details on how to do it from there, or fork it, make whatever changes are necessary, and then give a pr.

With the ability to clearly reproduce this, we can't help

On Tue, Mar 21, 2017, 6:41 AM Taylor Mathewson [email protected] wrote:

So I'm using spring boot, katharsis-spring and katharsis-jpa. katharsis version is 2.8.2, spring boot version is 1.4.2 I've got an object (hypothetically Car) which aggregates some other objects (hypothetically Car has Wheels in a list). If I annotate the aggregated objects (Wheel) with @JsonApiResource, this fails and throws the exception. Sorry I can't be more explicit, hope this helps.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/katharsis-project/katharsis-framework/issues/339#issuecomment-288081189, or mute the thread https://github.com/notifications/unsubscribe-auth/ABaI0HVMDJEZ1L_nW-ESlcnSgIjvvoJfks5rn9OKgaJpZM4MScY6 .

chb0github avatar Mar 21 '17 13:03 chb0github

@chb0github will do the moment I have time. @Ramblurr /api/car/1/wheels

taylormathewson avatar Mar 21 '17 13:03 taylormathewson

@taylormathewson Is the wheels resource coming from a different jar (i.e. via a maven dependency)?

dvtoever avatar Mar 30 '17 14:03 dvtoever

Without an example to reproduce we will end up closing the issue.

chb0github avatar Mar 30 '17 16:03 chb0github