11package ru .javaops .topjava .app .config ;
22
33import com .fasterxml .jackson .annotation .JsonAutoDetect ;
4- import com .fasterxml .jackson .databind .ObjectMapper ;
5- import com .fasterxml .jackson .datatype .hibernate6 .Hibernate6Module ;
4+ import com .fasterxml .jackson .annotation .PropertyAccessor ;
65import lombok .extern .slf4j .Slf4j ;
76import org .h2 .tools .Server ;
8- import org .springframework .beans .factory .annotation .Autowired ;
97import org .springframework .cache .annotation .EnableCaching ;
108import org .springframework .context .annotation .Bean ;
119import org .springframework .context .annotation .Configuration ;
1210import org .springframework .context .annotation .Profile ;
1311import org .springframework .http .ProblemDetail ;
1412import org .springframework .http .converter .json .ProblemDetailJacksonMixin ;
1513import ru .javaops .topjava .common .util .JsonUtil ;
14+ import tools .jackson .databind .ObjectMapper ;
15+ import tools .jackson .databind .json .JsonMapper ;
16+ import tools .jackson .datatype .hibernate7 .Hibernate7Module ;
1617
1718import java .sql .SQLException ;
1819
@@ -36,11 +37,21 @@ Server h2Server() throws SQLException {
3637 interface MixIn extends ProblemDetailJacksonMixin {
3738 }
3839
39- @ Autowired
40- void configureAndStoreObjectMapper (ObjectMapper objectMapper ) {
41- objectMapper .registerModule (new Hibernate6Module ());
42- // ErrorHandling: https://stackoverflow.com/questions/7421474/548473
43- objectMapper .addMixIn (ProblemDetail .class , MixIn .class );
44- JsonUtil .setMapper (objectMapper );
40+ // https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide#upgrading-jackson
41+ @ Bean
42+ ObjectMapper objectMapper () {
43+ ObjectMapper mapper = JsonMapper .builder ()
44+ .changeDefaultVisibility (visibilityChecker -> visibilityChecker
45+ .withVisibility (PropertyAccessor .FIELD , ANY )
46+ .withVisibility (PropertyAccessor .GETTER , NONE )
47+ .withVisibility (PropertyAccessor .SETTER , NONE )
48+ .withVisibility (PropertyAccessor .IS_GETTER , NONE )
49+ )
50+ .addModule (new Hibernate7Module ())
51+ // ErrorHandling: https://stackoverflow.com/questions/7421474/548473
52+ .addMixIn (ProblemDetail .class , MixIn .class )
53+ .build ();
54+ JsonUtil .setMapper (mapper );
55+ return mapper ;
4556 }
4657}
0 commit comments