9

I'm trying to setup a new application with latest SpringBoot 3 and everything works fine until I try to create and run my application with Native compilation. Just for your reference here is error that I receive from running unit tests:

 Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `*****`: cannot deserialize from Object value (no delegate- or property-based Creator): this appears to be a native image, in which case you may need to configure reflection for the class that is to be deserialized at [Source: (String)"[{"T":"success","msg":"authenticated"}]"; line: 1, column: 3] (through reference chain: java.util.ArrayList[0]) com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1909) com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:408) com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1349) com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1417) com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:352) 

I'm trying to convert JSON string to Object. It works fine when I run it as regular JAR , but it fails with I compile with Navite (GraalVM).

3 Answers 3

6

in spring native, Jackson doesn't know how to serialize/deserialize objects without prior knowledge about them, since it must know all the types in compile time.
to run your app in a native mode, you will need to register hints with knowledge about needed proxies, reflected methods, additional resource files/paths, or objects to serialize/deserialize.
to do so, implement the RuntimeHintsRegistrar interface. you can see an example in the docs

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for the help and documentation, I was missing this part of the documentation about how to provide the HINT to native image !!!
3

You may want to use @RegisterReflectionForBinding annotation for JSON mapping with jackson while working with RestTemplate or WebClient. More information in the docs

@RegisterReflectionForBinding({MyObject.class}) 

Comments

0

Have same jackson exception for MyClass which used in code and not only for jackson, so native image compiler for sure put that class into the native image, so I guess the issue is specific to jackson.

It is not so clear from documentation the difference between when to implement RuntimeHintsRegistrar and when to use @RegisterReflectionForBinding.

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `MyClass`: cannot deserialize from Object value (no delegate- or property-based Creator): this appears to be a native image, in which case you may need to configure reflection for the class that is to be deserialized at [Source: (ByteArrayInputStream); line: 1, column: 2] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.