Java 17: implementing Custom Record Serialization in Spring Boot with Jackson
I've tried everything I can think of but I'm trying to figure out I've been struggling with this for a few days now and could really use some help..... I've looked through the documentation and I'm still confused about I'm working with an scenario with serializing a custom Java Record in a Spring Boot application while using Jackson for JSON processing. The record is defined as follows: ```java import com.fasterxml.jackson.annotation.JsonProperty; public record User(@JsonProperty("id") long id, @JsonProperty("name") String name) {} ``` When I attempt to return a list of `User` records from my REST controller, I receive a `JsonMappingException` indicating that Jackson want to find a property called 'id'. Here's the relevant part of my controller: ```java import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Arrays; @RestController public class UserController { @GetMapping("/users") public List<User> getUsers() { return Arrays.asList(new User(1, "John Doe"), new User(2, "Jane Smith")); } } ``` I have Jackson version `2.12.5` in my `pom.xml`, and my `application.properties` has the following configuration: ```properties spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false ``` Despite this setup, I still receive the following behavior when I hit the `/users` endpoint: ``` com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class [record] and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ``` I've tried adding `@JsonCreator` to the constructor of my record, but that didn't seem to resolve the scenario. Hereβs how I attempted it: ```java @JsonCreator public record User(@JsonProperty("id") long id, @JsonProperty("name") String name) {} ``` However, the behavior continues. Additionally, I confirmed that my Spring Boot version is `2.6.3`. What am I missing in terms of configuration or annotations to properly serialize my record? Any insights would be greatly appreciated! Thanks in advance! I'm developing on Windows 10 with Java. I'd really appreciate any guidance on this. Any ideas what could be causing this?