0

I'm currently struggling to implement a restfull api using -> Spring Boot 3.0.0, using spring data rest and spring hateoas -> Spring native support

Basically, I would like to patch an entity, submitting a new value for a field (pointing to an existing entity in Database).

The reference is handled with an hal link. below is the Json object I "PATCH" to my EntityRepository controller:

{
  "shouldBeChecked": true,
  "name": "Amical6",
  "parent": null,
  "authority": "https://myurl/api/authorities/e52cdfb6-6f3c-4552-8ea4-e1357b5d052c"
}

Everything is fine when I run the app from my IDE (without GraalVM Native compilation). But when I go live on my test environment (copiled with GraalVM), I get the following errors :

in the web navigator (running the client app):

{"cause":{"cause":null,"message":"Cannot construct instance of `org.[xxx].Authority` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('https://myurl/api/authorities/e52cdfb6-6f3c-4552-8ea4-e1357b5d052c')\n at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: org.[xxx].MyObject[\"authority\"])"},"message":"Could not read payload"}

And, in my application logs :

 Failed to evaluate Jackson deserialization for type [[simple type, class org.springframework.data.rest.webmvc.PersistentEntityResource]]: java.lang.NullPointerException

I'm pretty sure I've got to add some Native Hints related to Jackson (or maybe Spring hateoas ?). Could someone help me with this?

Regards,


EDIT 2022.11.30 Please find below a small reproducer project: https://github.com/mathieupedreropro/spring-hal-jackson-graalvm

TLDR

I tried to use Spring Hateoas link handling to patch data to my Rest Webservice in a Native compiled Spring boot 3.0.0 application.

It fails at runtime, when the same application works like a charm using a traditional JDK

  • can you put a small reproducer in github ? – ozkanpakdil Nov 26 '22 at 01:29
  • As soon as possible! (but unfortunately it won't be too soon :(. That's not a professional project, and i don't have enough times these days) – Mathieu Pedrero Nov 28 '22 at 15:34
  • `no String-argument constructor/factory method to deserialize` -- might be that it tries to find the method using reflection and fails just because it is not configured for reflective access? Did you provide reflection configuration? – peterz Nov 29 '22 at 07:49
  • I think you're right @peterz, and my whole point is finding out what's missing in my reflective hints (programmatic reflective configuration that's converted into reflective access configuration suitable for graalVM by Spring at build time. As suggested ozkanpakdil, I created a small reproducer I'm going to publish to show you more. – Mathieu Pedrero Nov 29 '22 at 18:11
  • 1
    @ozkanpakdil here is my reproducer :) : https://github.com/mathieupedreropro/spring-hal-jackson-graalvm – Mathieu Pedrero Nov 30 '22 at 08:04
  • The easiest way to find out is probably to use the agent, then examine the config file it creates. Did you try that? – peterz Nov 30 '22 at 08:48
  • I don't know if it's what you meant, but here is the generaated config files (https://github.com/mathieupedreropro/spring-hal-jackson-graalvm/tree/main/generated-config). But now I struggle to find out what's missing there – Mathieu Pedrero Dec 02 '22 at 22:44
  • I dont think this is related to reflection. and there is this warning ```2022-12-03T16:20:30.573Z WARN 335356 --- [0.0-9090-exec-1] tion$ResourceSupportHttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class org.springframework.data.rest.webmvc.PersistentEntityResource]]: java.lang.NullPointerException ``` – ozkanpakdil Dec 03 '22 at 16:30
  • @ozkanpakdil Do you think this could be a bug (at Spring, jackson or... graalvm side ) ? Moreover, I tried to debug this NPE. But I struggle as I perform debug over code compiled with an usual JDK. Do you know if i can perform debug over native code if i Install graalVM on my computer ? – Mathieu Pedrero Dec 05 '22 at 13:47
  • I think this is spring or hal explorer bug. I have been working with jackson and spring https://github.com/ozkanpakdil/test-microservice-frameworks/tree/main/spring-boot-web and without reflection config it is working, https://www.graalvm.org/22.2/reference-manual/native-image/guides/debug-native-image-process/ probably you can debug it with local graalvm – ozkanpakdil Dec 05 '22 at 15:26
  • 1
    I don't think it's a hal explorer bug, as I face the same issue with my own html/js client app. So I submitted the following issue : https://github.com/spring-projects/spring-boot/issues/33468 – Mathieu Pedrero Dec 05 '22 at 20:37

0 Answers0