[JAVA-26374-boot-data] Moved "Spring Boot: Customize the Jackson ObjectMapper" article to spring-boot-data (#15095)
This commit is contained in:
parent
346350db14
commit
05230cf79d
|
@ -1,7 +1,6 @@
|
|||
### Relevant Articles:
|
||||
|
||||
- [HttpMessageNotWritableException: No Converter for [class …] With Preset Content-Type](https://www.baeldung.com/spring-no-converter-with-preset)
|
||||
- [Spring Boot: Customize the Jackson ObjectMapper](https://www.baeldung.com/spring-boot-customize-jackson-objectmapper)
|
||||
- [“HttpMessageNotWritableException: No converter found for return value of type”](https://www.baeldung.com/spring-no-converter-found)
|
||||
- [Creating a Read-Only Repository with Spring Data](https://www.baeldung.com/spring-data-read-only-repository)
|
||||
- [Using JaVers for Data Model Auditing in Spring Data](https://www.baeldung.com/spring-data-javers-audit)
|
||||
|
|
|
@ -11,4 +11,5 @@ This module contains articles about Spring Boot with Spring Data
|
|||
- [Spring Custom Property Editor](https://www.baeldung.com/spring-mvc-custom-property-editor)
|
||||
- [Using @JsonComponent in Spring Boot](https://www.baeldung.com/spring-boot-jsoncomponent)
|
||||
- [Guide To Running Logic on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring)
|
||||
- [Spring Boot: Customize the Jackson ObjectMapper](https://www.baeldung.com/spring-boot-customize-jackson-objectmapper)
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.baeldung.boot.jackson.config;
|
||||
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
|
||||
public class CoffeeConstants {
|
||||
|
||||
public static final String DATETIME_FORMAT = "dd-MM-yyyy HH:mm";
|
|
@ -1,11 +1,12 @@
|
|||
package com.baeldung.boot.jackson.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@Configuration
|
||||
public class CoffeeCustomizerConfig {
|
|
@ -1,12 +1,13 @@
|
|||
package com.baeldung.boot.jackson.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@Configuration
|
||||
public class CoffeeHttpConverterConfiguration {
|
|
@ -1,12 +1,13 @@
|
|||
package com.baeldung.boot.jackson.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@Configuration
|
||||
public class CoffeeJacksonBuilderConfig {
|
|
@ -1,13 +1,14 @@
|
|||
package com.baeldung.boot.jackson.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
@Configuration
|
||||
public class CoffeeObjectMapperConfig {
|
|
@ -1,19 +1,19 @@
|
|||
package com.baeldung.boot.jackson.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.LOCAL_DATETIME_SERIALIZER;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:coffee.properties")
|
||||
public class CoffeeRegisterModuleConfig {
|
||||
|
||||
@Bean
|
||||
public Module javaTimeModule() {
|
||||
public JavaTimeModule javaTimeModule() {
|
||||
JavaTimeModule module = new JavaTimeModule();
|
||||
module.addSerializer(LOCAL_DATETIME_SERIALIZER);
|
||||
return module;
|
|
@ -1,11 +1,12 @@
|
|||
package com.baeldung.boot.jackson.controller;
|
||||
|
||||
import com.baeldung.boot.jackson.model.Coffee;
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.FIXED_DATE;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.FIXED_DATE;
|
||||
import com.baeldung.boot.jackson.model.Coffee;
|
||||
|
||||
@RestController
|
||||
public class CoffeeController {
|
|
@ -1,15 +1,16 @@
|
|||
package com.baeldung.boot.jackson.app;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeConstants;
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.FIXED_DATE;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import static com.baeldung.boot.jackson.config.CoffeeConstants.FIXED_DATE;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import com.baeldung.boot.jackson.config.CoffeeConstants;
|
||||
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public abstract class AbstractCoffeeIntegrationTest {
|
|
@ -1,8 +1,9 @@
|
|||
package com.baeldung.boot.jackson.app;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeCustomizerConfig;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeCustomizerConfig;
|
||||
|
||||
@Import(CoffeeCustomizerConfig.class)
|
||||
public class CoffeeCustomizerIntegrationTest extends AbstractCoffeeIntegrationTest {
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package com.baeldung.boot.jackson.app;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeHttpConverterConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeHttpConverterConfiguration;
|
||||
|
||||
@Import(CoffeeHttpConverterConfiguration.class)
|
||||
public class CoffeeHttpConverterIntegrationTest extends AbstractCoffeeIntegrationTest {
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package com.baeldung.boot.jackson.app;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeJacksonBuilderConfig;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeJacksonBuilderConfig;
|
||||
|
||||
@Import(CoffeeJacksonBuilderConfig.class)
|
||||
public class CoffeeJacksonBuilderIntegrationTest extends AbstractCoffeeIntegrationTest {
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package com.baeldung.boot.jackson.app;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeObjectMapperConfig;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeObjectMapperConfig;
|
||||
|
||||
@Import(CoffeeObjectMapperConfig.class)
|
||||
public class CoffeeObjectMapperIntegrationTest extends AbstractCoffeeIntegrationTest {
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package com.baeldung.boot.jackson.app;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeRegisterModuleConfig;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import com.baeldung.boot.jackson.config.CoffeeRegisterModuleConfig;
|
||||
|
||||
@Import(CoffeeRegisterModuleConfig.class)
|
||||
public class CoffeeRegisterModuleIntegrationTest extends AbstractCoffeeIntegrationTest {
|
||||
}
|
Loading…
Reference in New Issue