Closed edudar closed 1 year ago
I guess you need the chaining for reflection hints (@TypeHint
) so that JSON serialization works, and not for @SerializationHint
. @SerializationHint
is for Java serialization (ObjectOutputStream
, ...). Correct?
FWIW Spring Framework 6 will provide some reusable helper to register the relevant type, not only in @RequestMapping
context, but also applied to other ones.
@mhalbritter oops, my bad, mixed up serializations. That, however, seems to be a very niche feature for a rather generic TypeHint
.
For example: @SerializationHint(types = Config.class, chain = false) public class MyController {
@GetMapping("/_system/_configs")
public List<Config> configs() { return List.of(); }
@GetMapping("/_system/_services")
public List<Service> services() { return List.of(); }
@GetMapping("/_system/_endpoints")
public List<EndpointsList> endpoints() { return List.of(); }
} This will serialize only the Config, Service, and EndpointsList types, and not their dependencies.
It's also worth noting that the @SerializationHint annotation is not used to specify which classes should be scanned by Spring Native. Spring Native will scan all classes that are reachable from the root object being serialized, regardless of whether they are annotated with @SerializationHint. If you want to exclude certain classes from being scanned, you can use the @NoScan annotation.
Spring Native is now superseded by Spring Boot 3 official native support, see the related reference documentation for more details.
As a consequence, I am closing this issue, and recommend trying your use case with latest Spring Boot 3 version. If you still experience the issue reported here, please open an issue directly on the related Spring project (Spring Framework, Data, Security, Boot, Cloud, etc.) with a reproducer.
Thanks for your contribution on the experimental Spring Native project, we hope you will enjoy the official native support introduced by Spring Boot 3.
I'm trying to run a native image with Kubernetes support via the fabric8 client. It loads a few model hierarchies like
io.fabric8.kubernetes.api.model.Config
,.Service
,.EndpointsList
, etc for operations. Each hierarchy is quite extensive, I tried listing classes via@SerializationHint
, but it becomes too enduring and the list is way too long. I learned in #1569 that Spring Native scan classes in responses down the chain, so I added the following into one of the controllers:It would be good to have such a feature in
@SerializationHint(types = Config.class, chain = true)
that will befalse
by default.