The serialization and deserialization issue of Feign Client Jackson can be addressed in Spring Boot 3 native image by following these steps:
Use the jackson-databind-json-format-module
dependency: Add this dependency to your pom.xml
file or Gradle build file.
Configure the serialization and deserialization features: Configure the serialization and deserialization features by adding the following code to your Spring Boot application configuration class:
@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
return objectMapper;
}
@Bean
public Decoder feignDecoder() {
return new JacksonDecoder(objectMapper());
}
@Bean
public Encoder feignEncoder() {
return new JacksonEncoder(objectMapper());
}
./mvnw clean package -DskipTests -Pnative
./target/{application-name}
Where {application-name}
is the name of your Spring Boot application.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-01-26 11:00:00 +0000
Seen: 12 times
Last updated: Aug 14 '21