1717
1818import static org .mockito .Mockito .*;
1919
20+ import tools .jackson .databind .DeserializationFeature ;
21+ import tools .jackson .databind .ObjectMapper ;
22+ import tools .jackson .databind .json .JsonMapper ;
23+ import tools .jackson .databind .module .SimpleModule ;
24+
2025import java .util .Collections ;
2126import java .util .List ;
2227
3035import org .springframework .data .repository .support .DefaultRepositoryInvokerFactory ;
3136import org .springframework .data .repository .support .DomainClassConverter ;
3237import org .springframework .data .repository .support .Repositories ;
38+ import org .springframework .data .repository .support .RepositoryInvokerFactory ;
3339import org .springframework .data .rest .core .UriToEntityConverter ;
3440import org .springframework .data .rest .core .config .EnumTranslationConfiguration ;
3541import org .springframework .data .rest .core .config .MetadataConfiguration ;
4046import org .springframework .data .rest .core .support .EntityLookup ;
4147import org .springframework .data .rest .core .support .SelfLinkProvider ;
4248import org .springframework .data .rest .webmvc .EmbeddedResourcesAssembler ;
43- import org .springframework .data .rest .webmvc .json .PersistentEntityJackson2Module ;
44- import org .springframework .data .rest .webmvc .json .PersistentEntityJackson2Module .LookupObjectSerializer ;
49+ import org .springframework .data .rest .webmvc .json .PersistentEntityJackson3Module ;
50+ import org .springframework .data .rest .webmvc .json .PersistentEntityJackson3Module .LookupObjectSerializer ;
4551import org .springframework .data .rest .webmvc .mapping .Associations ;
4652import org .springframework .data .rest .webmvc .mapping .DefaultLinkCollector ;
4753import org .springframework .data .rest .webmvc .mapping .LinkCollector ;
5359import org .springframework .format .support .FormattingConversionService ;
5460import org .springframework .hateoas .mediatype .MessageResolver ;
5561import org .springframework .hateoas .mediatype .hal .DefaultCurieProvider ;
56- import org .springframework .hateoas .mediatype .hal .Jackson2HalModule ;
62+ import org .springframework .hateoas .mediatype .hal .HalJacksonModule ;
63+ import org .springframework .hateoas .mediatype .hal .HalJacksonModule .HalHandlerInstantiator ;
5764import org .springframework .hateoas .server .EntityLinks ;
5865import org .springframework .hateoas .server .LinkRelationProvider ;
5966import org .springframework .hateoas .server .RepresentationModelProcessor ;
6067import org .springframework .hateoas .server .core .EvoInflectorLinkRelationProvider ;
6168import org .springframework .hateoas .server .mvc .RepresentationModelProcessorInvoker ;
6269import org .springframework .plugin .core .PluginRegistry ;
6370
64- import com .fasterxml .jackson .annotation .JsonInclude .Include ;
65- import com .fasterxml .jackson .databind .DeserializationFeature ;
66- import com .fasterxml .jackson .databind .Module ;
67- import com .fasterxml .jackson .databind .ObjectMapper ;
68-
6971/**
7072 * @author Jon Brisbin
7173 * @author Greg Turnquist
@@ -107,7 +109,7 @@ public PersistentEntities persistentEntities() {
107109 }
108110
109111 @ Bean
110- public Module persistentEntityModule () {
112+ public SimpleModule persistentEntityModule () {
111113
112114 var conversionService = new DefaultConversionService ();
113115
@@ -118,14 +120,14 @@ public Module persistentEntityModule() {
118120 SelfLinkProvider selfLinkProvider = new DefaultSelfLinkProvider (persistentEntities (), entityLinks ,
119121 Collections .<EntityLookup <?>> emptyList (), conversionService );
120122
121- DefaultRepositoryInvokerFactory invokerFactory = new DefaultRepositoryInvokerFactory (repositories ());
123+ RepositoryInvokerFactory invokerFactory = new DefaultRepositoryInvokerFactory (repositories ());
122124 UriToEntityConverter uriToEntityConverter = new UriToEntityConverter (persistentEntities (), invokerFactory ,
123125 () -> conversionService );
124126
125127 Associations associations = new Associations (mappings , config ());
126128 LinkCollector collector = new DefaultLinkCollector (persistentEntities (), selfLinkProvider , associations );
127129
128- return new PersistentEntityJackson2Module (associations , persistentEntities (), uriToEntityConverter , collector ,
130+ return new PersistentEntityJackson3Module (associations , persistentEntities (), uriToEntityConverter , collector ,
129131 invokerFactory , mock (LookupObjectSerializer .class ),
130132 new RepresentationModelProcessorInvoker (Collections .<RepresentationModelProcessor <?>> emptyList ()),
131133 new EmbeddedResourcesAssembler (persistentEntities (), associations , mock (ExcerptProjector .class )));
@@ -135,15 +137,13 @@ invokerFactory, mock(LookupObjectSerializer.class),
135137 public ObjectMapper objectMapper () {
136138
137139 LinkRelationProvider relProvider = new EvoInflectorLinkRelationProvider ();
138- ObjectMapper mapper = new ObjectMapper ();
139-
140- mapper .registerModule (new Jackson2HalModule ());
141- mapper .registerModule (persistentEntityModule ());
142- mapper .setHandlerInstantiator (new Jackson2HalModule .HalHandlerInstantiator (relProvider ,
143- new DefaultCurieProvider (Collections .emptyMap ()), MessageResolver .DEFAULTS_ONLY ));
144- mapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
145- mapper .setSerializationInclusion (Include .NON_EMPTY );
146140
147- return mapper ;
141+ return JsonMapper .builder ()
142+ .addModule (new HalJacksonModule ())
143+ .addModule (persistentEntityModule ())
144+ .handlerInstantiator (new HalHandlerInstantiator (relProvider ,
145+ new DefaultCurieProvider (Collections .emptyMap ()), MessageResolver .DEFAULTS_ONLY ))
146+ .disable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
147+ .build ();
148148 }
149149}
0 commit comments