Skip to content

Commit b20d28e

Browse files
authored
Upgrade to spring-boot 4 (#922)
* bump spring-boot-starter-parent from 3.5.14 to 4.1.0 (latest) * Upgrade to Jackson 3 (#934) * upgrade fairdatateam packages: - bump spring-security-acl-mongodb version from 6.0.4 to 6.0.5 - bump rdf-resource-resolver version from 0.2.0 to 0.2.2 - bump spring-rdf-migration version from 2.0.0 to 2.0.1 * replace spring.data.mongodb by spring.mongodb in application.yml see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Configuration-Changelog * rename spring-boot-starter-aop to spring-boot-starter-aspectj see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide#aop-starter-pom * replace deprecated spring-boot-starter-web by spring-boot-starter-webmvc and replace spring-boot-starter-test by spring-boot-starter-webmvc-test (which brings in spring-boot-starter-test as transitive dependency) https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide#deprecated-starters https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide#test-code * remove android-json exclusion from spring-boot-starter-test, as it does not appear to do anything * replace spring-security-test by spring-boot-starter-security-test, as mentioned in https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide#test-code * remove redundant spring-data-mongodb dependency, because this is already pulled in by spring-boot-starter-data-mongodb (via spring-boot-starter-mongodb) https://central.sonatype.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb/4.0.6 https://central.sonatype.com/artifact/org.springframework.boot/spring-boot-data-mongodb/4.0.6 * replace deprecated PersistenceConstructor by PersistenceCreator (cannot find this in spring-data-commons release notes, but see e.g. spring-projects/spring-data-neo4j@1c11be9) * add spring-boot-starter-restclient and corresponding test starter, fix corresponding RestTemplateBuilder import, and replace deprecated setConnectionTimeout and setReadTimeout calls https://docs.spring.io/spring-boot/3.4/api/java/org/springframework/boot/web/client/RestTemplateBuilder.html * fix imports for AutoConfigureMockMvc and AutoConfigureMockRestServiceServer, because these have been moved from org.springframework.boot.test.autoconfigure.web to two different packages * add spring-boot-starter-micrometer-metrics dependency and fix corresponding metrics imports (see spring-projects/spring-boot#50788) * revert spring-boot-starter-micrometer-metrics dependency because spring-boot-starter-actuator already pulls that in (see https://github.com/spring-projects/spring-boot/blob/2edca39504f8e9c2943262d3e60ba34b0e7751ac/starter/spring-boot-starter-actuator/build.gradle#L25) * remove unused setFromHttpEntity method, because, not only is it unused, but it gives rise to the following error in spring-boot 4: "incompatible types: org.springframework.http.HttpHeaders cannot be converted to java.util.Map<java.lang.String,java.util.List<java.lang.String>>" * fix TestRestTemplate imports (class has been moved to org.springframework.boot.resttestclient package in spring-boot 4) * replace ClientHttpRequestFactorySettings.Redirects by HttpRedirects because org.springframework.boot.http.client.ClientHttpRequestFactorySettings has been removed, apparently * fix HttpHeaders assertions because the class no longer extends MultiValueMap * rearrange httpclient5 dependency (this was listed under 'Test' dependencies, but does not specify the test scope) * explicit dependency on jakarta.servlet-api This is available via spring-boot starters (jetty?), but we depend heavily on this package and import explicitly from it, so better make the dependency explicit. The package version is managed by spring boot. https://docs.spring.io/spring-boot/appendix/dependency-versions/coordinates.html * bump springdoc-openapi-starter-webmvc-ui from 2.8.16 to 3.0.3, for compatibility with spring-boot 4 (spring 7) * add @AutoConfigureTestRestTemplate to WebIntegrationTest because @SpringBootTest no longer provides the TestRestTemplate bean, as mentioned in the migration guide: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide#using-webclient-or-testresttemplate-and-springboottest * make setup() public in HarvesterServiceTest * clean up spring-boot-starters, following the spring-boot-starter-classic workflow described in the spring boot 4 migration guide * explicit jackson dependency: we import directly from the jackson packages in many places, so the dependency should be explicit instead of only transitive * explicit dependency on spring-boot-data-mongodb * use jspecify @nullable in AbstractMetadataRepository (this is the only use of @nullable in the fdp) * handle null in ResourceDefinitionTargetClassesCache to get rid of the nullpointerexceptions in tests, like: "Cannot invoke org.fairdatateam.fairdatapoint.entity.schema.MetadataSchema.getTargetClasses() because the return value of java.util.Map.get(Object) is null at org.fairdatateam.fairdatapoint.service.resource.ResourceDefinitionTargetClassesCache.lambda$computeCache$2(ResourceDefinitionTargetClassesCache.java:84)" * fix style for ResourceDefinitionTargetClassesCache * configure mongodb uuid representation an alternative would be something like: ```java @configuration public class MongoClientConfig extends AbstractMongoClientConfiguration { @value("${spring.mongodb.database}") private String databaseName; @OverRide protected void configureClientSettings(MongoClientSettings.Builder builder) { builder.uuidRepresentation(UuidRepresentation.STANDARD); } @OverRide protected @nonnull String getDatabaseName() { return databaseName; } } ``` https://docs.spring.io/spring-data/mongodb/reference/migration-guide/migration-guide-4.x-to-5.x.html * explicit no-args constructor for MetadataSchemaDraftDTO marked as @JsonCreator (fixes the "Cannot map `null` into type `boolean`" error) also see FasterXML/jackson-databind#5318 and https://github.com/FasterXML/jackson/wiki/Jackson-Release-3.0#jackson-databind * change MetadataSchemaDraftDTO.abstractSchema boolean to Boolean this fixes the following error: "Cannot map null into type boolean (set DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES to 'false' to allow)" * replace ObjectMapper by JsonMapper with new builder api - fix corresponding imports: com.fasterxml.jackson moved to tools.jackson except for com.fasterxml.jackson.annotation - replace JsonProcessingException by JacksonException - replace MappingJackson2HttpMessageConverter by JacksonJsonHttpMessageConverter * switch WebMvcConfig to constructor autowiring, while we're at it * update configureMessageConverters to use ServerBuilder because the original method is deprecated for removal * annotate ContentNegotiationConfigurer NonNull to match parent signature * explicit dependency on slf4j, because it is used explicitly throughout the code, but was only included transitively (implicitly)
1 parent 888b539 commit b20d28e

29 files changed

Lines changed: 172 additions & 135 deletions

pom.xml

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.5.15</version>
8+
<version>4.1.0</version>
9+
<!-- spring-boot managed dependencies: https://docs.spring.io/spring-boot/appendix/dependency-versions/coordinates.html -->
910
<relativePath/> <!-- lookup parent from repository -->
1011
</parent>
1112
<groupId>org.fairdatateam</groupId>
@@ -54,12 +55,12 @@
5455
<maven.compiler.target>21</maven.compiler.target>
5556

5657
<!-- Project related -->
57-
<spring-rdf-migration.version>2.0.0</spring-rdf-migration.version>
58-
<rdf-resource-resolver.version>0.2.0</rdf-resource-resolver.version>
59-
<spring-security-acl-mongodb.version>6.0.4</spring-security-acl-mongodb.version>
58+
<spring-rdf-migration.version>2.0.1</spring-rdf-migration.version>
59+
<rdf-resource-resolver.version>0.2.2</rdf-resource-resolver.version>
60+
<spring-security-acl-mongodb.version>6.0.5</spring-security-acl-mongodb.version>
6061

6162
<!-- Core -->
62-
<springdoc-openapi-starter-webmvc-ui.version>2.8.16</springdoc-openapi-starter-webmvc-ui.version>
63+
<springdoc-openapi-starter-webmvc-ui.version>3.0.3</springdoc-openapi-starter-webmvc-ui.version>
6364
<mongock-bom.version>5.5.1</mongock-bom.version>
6465
<rdf4j-runtime.version>5.3.1</rdf4j-runtime.version>
6566
<jjwt-api.version>0.13.0</jjwt-api.version>
@@ -127,9 +128,10 @@
127128
<!-- ////////////////// -->
128129
<!-- Spring -->
129130
<!-- ////////////////// -->
131+
130132
<dependency>
131133
<groupId>org.springframework.boot</groupId>
132-
<artifactId>spring-boot-starter-web</artifactId>
134+
<artifactId>spring-boot-starter-actuator</artifactId>
133135
<exclusions>
134136
<exclusion>
135137
<!-- excluded because we're using spring-boot-starter-log4j2 instead (see spring-boot logging docs) -->
@@ -140,40 +142,75 @@
140142
</dependency>
141143
<dependency>
142144
<groupId>org.springframework.boot</groupId>
143-
<artifactId>spring-boot-starter-security</artifactId>
145+
<artifactId>spring-boot-starter-aspectj</artifactId>
144146
</dependency>
145147
<dependency>
146148
<groupId>org.springframework.boot</groupId>
147-
<artifactId>spring-boot-starter-log4j2</artifactId>
149+
<artifactId>spring-boot-starter-jackson</artifactId>
148150
</dependency>
149151
<dependency>
150152
<groupId>org.springframework.boot</groupId>
151-
<artifactId>spring-boot-configuration-processor</artifactId>
153+
<artifactId>spring-boot-starter-log4j2</artifactId>
152154
</dependency>
153155
<dependency>
154156
<groupId>org.springframework.boot</groupId>
155157
<artifactId>spring-boot-starter-data-mongodb</artifactId>
156158
</dependency>
157159
<dependency>
158-
<groupId>org.springframework.security</groupId>
159-
<artifactId>spring-security-acl</artifactId>
160+
<groupId>org.springframework.boot</groupId>
161+
<artifactId>spring-boot-starter-data-mongodb-test</artifactId>
162+
<scope>test</scope>
160163
</dependency>
161164
<dependency>
162165
<groupId>org.springframework.boot</groupId>
163-
<artifactId>spring-boot-starter-actuator</artifactId>
166+
<artifactId>spring-boot-starter-restclient</artifactId>
167+
</dependency>
168+
<dependency>
169+
<groupId>org.springframework.boot</groupId>
170+
<artifactId>spring-boot-starter-restclient-test</artifactId>
171+
<scope>test</scope>
164172
</dependency>
165173
<dependency>
174+
<!-- https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide#testresttemplate-failures -->
175+
<!-- todo: remove in favor of restclient, see #897 -->
166176
<groupId>org.springframework.boot</groupId>
167-
<artifactId>spring-boot-starter-aop</artifactId>
177+
<artifactId>spring-boot-resttestclient</artifactId>
178+
<scope>test</scope>
168179
</dependency>
169180
<dependency>
181+
<groupId>org.springframework.boot</groupId>
182+
<artifactId>spring-boot-starter-security</artifactId>
183+
</dependency>
184+
<dependency>
185+
<groupId>org.springframework.boot</groupId>
186+
<artifactId>spring-boot-starter-security-test</artifactId>
187+
<scope>test</scope>
188+
</dependency>
189+
<dependency>
190+
<!-- with transitive dependency on hibernate-validator -->
170191
<groupId>org.springframework.boot</groupId>
171192
<artifactId>spring-boot-starter-validation</artifactId>
172193
</dependency>
194+
<dependency>
195+
<groupId>org.springframework.boot</groupId>
196+
<artifactId>spring-boot-starter-validation-test</artifactId>
197+
<scope>test</scope>
198+
</dependency>
199+
<dependency>
200+
<groupId>org.springframework.boot</groupId>
201+
<artifactId>spring-boot-starter-webmvc</artifactId>
202+
</dependency>
203+
<dependency>
204+
<groupId>org.springframework.boot</groupId>
205+
<artifactId>spring-boot-starter-webmvc-test</artifactId>
206+
<scope>test</scope>
207+
</dependency>
173208

174209
<!-- ////////////////// -->
175210
<!-- Mongock -->
176211
<!-- ////////////////// -->
212+
213+
<!-- mongock versions are managed via mongock-bom -->
177214
<dependency>
178215
<groupId>io.mongock</groupId>
179216
<artifactId>mongock-springboot</artifactId>
@@ -182,10 +219,6 @@
182219
<groupId>io.mongock</groupId>
183220
<artifactId>mongodb-springdata-v4-driver</artifactId>
184221
</dependency>
185-
<dependency>
186-
<groupId>org.springframework.data</groupId>
187-
<artifactId>spring-data-mongodb</artifactId>
188-
</dependency>
189222

190223
<!-- ////////////////// -->
191224
<!-- Core -->
@@ -238,30 +271,19 @@
238271
<groupId>org.projectlombok</groupId>
239272
<artifactId>lombok</artifactId>
240273
</dependency>
241-
242-
<!-- ////////////////// -->
243-
<!-- Test -->
244-
<!-- ////////////////// -->
245274
<dependency>
246-
<groupId>org.springframework.boot</groupId>
247-
<artifactId>spring-boot-starter-test</artifactId>
248-
<scope>test</scope>
249-
<exclusions>
250-
<exclusion>
251-
<groupId>com.vaadin.external.google</groupId>
252-
<artifactId>android-json</artifactId>
253-
</exclusion>
254-
</exclusions>
275+
<groupId>org.apache.httpcomponents.client5</groupId>
276+
<artifactId>httpclient5</artifactId>
255277
</dependency>
256278
<dependency>
257-
<groupId>org.springframework.security</groupId>
258-
<artifactId>spring-security-test</artifactId>
259-
<scope>test</scope>
279+
<groupId>jakarta.servlet</groupId>
280+
<artifactId>jakarta.servlet-api</artifactId>
260281
</dependency>
261282
<dependency>
262-
<groupId>org.apache.httpcomponents.client5</groupId>
263-
<artifactId>httpclient5</artifactId>
283+
<groupId>org.slf4j</groupId>
284+
<artifactId>slf4j-api</artifactId>
264285
</dependency>
286+
265287
</dependencies>
266288

267289
<build>

src/main/java/org/fairdatateam/fairdatapoint/api/dto/schema/MetadataSchemaDraftDTO.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
*/
2323
package org.fairdatateam.fairdatapoint.api.dto.schema;
2424

25+
import com.fasterxml.jackson.annotation.JsonCreator;
2526
import com.fasterxml.jackson.annotation.JsonInclude;
2627
import jakarta.validation.constraints.NotBlank;
2728
import jakarta.validation.constraints.NotNull;
2829
import lombok.*;
2930

3031
import java.util.List;
3132

32-
@NoArgsConstructor
3333
@AllArgsConstructor
3434
@Getter
3535
@Setter
@@ -47,7 +47,7 @@ public class MetadataSchemaDraftDTO {
4747
@NotNull
4848
private String description;
4949

50-
private boolean abstractSchema;
50+
private Boolean abstractSchema;
5151

5252
@NotNull
5353
private String definition;
@@ -63,4 +63,13 @@ public class MetadataSchemaDraftDTO {
6363

6464
@JsonInclude(JsonInclude.Include.ALWAYS)
6565
private String lastVersion;
66+
67+
/**
68+
* No-args constructor explicitly marked as default for JSON creation.
69+
* See <a href="https://github.com/FasterXML/jackson/wiki/Jackson-Release-3.0#jackson-databind">
70+
* FasterXML/jackson-databind#5318</a> for more info.
71+
*/
72+
@JsonCreator
73+
public MetadataSchemaDraftDTO() {
74+
}
6675
}

src/main/java/org/fairdatateam/fairdatapoint/api/filter/JwtTokenFilter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
package org.fairdatateam.fairdatapoint.api.filter;
2424

25-
import com.fasterxml.jackson.databind.ObjectMapper;
2625
import jakarta.servlet.FilterChain;
2726
import jakarta.servlet.ServletException;
2827
import jakarta.servlet.http.HttpServletRequest;
@@ -38,6 +37,7 @@
3837
import org.springframework.security.core.context.SecurityContextHolder;
3938
import org.springframework.stereotype.Component;
4039
import org.springframework.web.filter.OncePerRequestFilter;
40+
import tools.jackson.databind.json.JsonMapper;
4141

4242
import java.io.IOException;
4343

@@ -53,7 +53,7 @@ public class JwtTokenFilter extends OncePerRequestFilter {
5353
private ApiKeyService apiKeyService;
5454

5555
@Autowired
56-
private ObjectMapper objectMapper;
56+
private JsonMapper jsonMapper;
5757

5858
@Override
5959
public void doFilterInternal(
@@ -69,7 +69,7 @@ public void doFilterInternal(
6969
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
7070
response.setContentType(MediaType.APPLICATION_JSON.toString());
7171
final ErrorDTO error = new ErrorDTO(HttpStatus.UNAUTHORIZED, "You have to be log in");
72-
objectMapper.writeValue(response.getWriter(), error);
72+
jsonMapper.writeValue(response.getWriter(), error);
7373
}
7474
}
7575

src/main/java/org/fairdatateam/fairdatapoint/config/ActuatorMetricsConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import io.micrometer.core.instrument.MeterRegistry;
2727
import io.micrometer.core.instrument.config.MeterFilter;
2828
import lombok.extern.slf4j.Slf4j;
29-
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
29+
import org.springframework.boot.micrometer.metrics.autoconfigure.MeterRegistryCustomizer;
3030
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
3131
import org.springframework.context.annotation.Bean;
3232
import org.springframework.context.annotation.Configuration;

src/main/java/org/fairdatateam/fairdatapoint/config/HttpClientConfig.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
package org.fairdatateam.fairdatapoint.config;
2424

25-
import org.springframework.boot.web.client.RestTemplateBuilder;
25+
import org.springframework.boot.restclient.RestTemplateBuilder;
2626
import org.springframework.context.annotation.Bean;
2727
import org.springframework.context.annotation.Configuration;
2828
import org.springframework.web.client.RestClient;
@@ -45,9 +45,8 @@ public class HttpClientConfig {
4545
@Bean
4646
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
4747
return restTemplateBuilder
48-
// todo: these are deprecated, but we should replace RestTemplate by RestClient anyway
49-
.setConnectTimeout(TIMEOUT)
50-
.setReadTimeout(TIMEOUT)
48+
.connectTimeout(TIMEOUT)
49+
.readTimeout(TIMEOUT)
5150
.build();
5251
}
5352

src/main/java/org/fairdatateam/fairdatapoint/config/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package org.fairdatateam.fairdatapoint.config;
2424

2525
import org.fairdatateam.fairdatapoint.api.filter.FilterConfigurer;
26-
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
26+
import org.springframework.boot.security.autoconfigure.actuate.web.servlet.EndpointRequest;
2727
import org.springframework.context.annotation.Bean;
2828
import org.springframework.context.annotation.Configuration;
2929
import org.springframework.http.HttpMethod;

src/main/java/org/fairdatateam/fairdatapoint/config/WebMvcConfig.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,58 @@
2222
*/
2323
package org.fairdatateam.fairdatapoint.config;
2424

25-
import com.fasterxml.jackson.databind.DeserializationFeature;
26-
import com.fasterxml.jackson.databind.ObjectMapper;
25+
import com.fasterxml.jackson.annotation.JsonInclude;
2726
import org.fairdatateam.fairdatapoint.api.converter.ErrorConverter;
2827
import org.fairdatateam.fairdatapoint.api.converter.RdfConverter;
29-
import org.springframework.beans.factory.annotation.Autowired;
28+
import org.jspecify.annotations.NonNull;
3029
import org.springframework.context.annotation.Bean;
3130
import org.springframework.context.annotation.Configuration;
3231
import org.springframework.context.annotation.Primary;
3332
import org.springframework.http.HttpHeaders;
3433
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
35-
import org.springframework.http.converter.HttpMessageConverter;
34+
import org.springframework.http.converter.HttpMessageConverters;
3635
import org.springframework.http.converter.StringHttpMessageConverter;
37-
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
36+
import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter;
3837
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
3938
import org.springframework.web.servlet.config.annotation.CorsRegistry;
4039
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
4140
import org.springframework.web.servlet.view.InternalResourceViewResolver;
41+
import tools.jackson.databind.DeserializationFeature;
42+
import tools.jackson.databind.json.JsonMapper;
4243

4344
import java.util.List;
4445

45-
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
46-
4746
@Configuration
4847
public class WebMvcConfig implements WebMvcConfigurer {
4948

50-
@Autowired
51-
private List<ErrorConverter> errorConverters;
49+
private final List<ErrorConverter> errorConverters;
5250

53-
@Autowired
54-
private List<RdfConverter> rdfConverters;
51+
private final List<RdfConverter> rdfConverters;
5552

53+
/**
54+
* Constructor (autowired)
55+
*/
56+
public WebMvcConfig(List<ErrorConverter> errorConverters, List<RdfConverter> rdfConverters) {
57+
this.errorConverters = errorConverters;
58+
this.rdfConverters = rdfConverters;
59+
}
60+
61+
/**
62+
* Configures message converters. See
63+
* <a href="https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-config/message-converters.html">
64+
* example in Spring docs</a>.
65+
*/
5666
@Override
57-
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
58-
converters.add(new StringHttpMessageConverter());
59-
converters.addAll(errorConverters);
60-
converters.addAll(rdfConverters);
61-
converters.add(new ByteArrayHttpMessageConverter());
62-
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
67+
public void configureMessageConverters(HttpMessageConverters.@NonNull ServerBuilder builder) {
68+
builder.withStringConverter(new StringHttpMessageConverter())
69+
.withJsonConverter(new JacksonJsonHttpMessageConverter(jsonMapper()))
70+
.addCustomConverter(new ByteArrayHttpMessageConverter());
71+
errorConverters.forEach(builder::addCustomConverter);
72+
rdfConverters.forEach(builder::addCustomConverter);
6373
}
6474

6575
@Override
66-
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
76+
public void configureContentNegotiation(@NonNull ContentNegotiationConfigurer configurer) {
6777
for (ErrorConverter converter : errorConverters) {
6878
converter.configureContentNegotiation(configurer);
6979
}
@@ -75,12 +85,15 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
7585

7686
@Bean
7787
@Primary
78-
public ObjectMapper objectMapper() {
79-
final ObjectMapper mapper = new ObjectMapper();
80-
mapper.findAndRegisterModules();
81-
mapper.setSerializationInclusion(NON_NULL);
82-
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
83-
return mapper;
88+
public JsonMapper jsonMapper() {
89+
return JsonMapper.builder()
90+
// https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.9.8/com/fasterxml/jackson/databind/ObjectMapper.html#findAndRegisterModules--
91+
// https://github.com/FasterXML/jackson/blob/main/jackson3/MIGRATING_TO_JACKSON_3.md#objectmapper-serialization-inclusion-configuration
92+
.changeDefaultPropertyInclusion(incl -> incl.withValueInclusion(JsonInclude.Include.NON_NULL))
93+
.changeDefaultPropertyInclusion(incl -> incl.withContentInclusion(JsonInclude.Include.NON_NULL))
94+
// https://github.com/FasterXML/jackson/blob/main/jackson3/MIGRATING_TO_JACKSON_3.md#objectmapper-visibility-configuration
95+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
96+
.build();
8497
}
8598

8699
@Bean

src/main/java/org/fairdatateam/fairdatapoint/database/rdf/repository/AbstractMetadataRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
package org.fairdatateam.fairdatapoint.database.rdf.repository;
2424

25-
import jakarta.annotation.Nullable;
2625
import lombok.extern.slf4j.Slf4j;
2726
import org.eclipse.rdf4j.common.iteration.Iterations;
2827
import org.eclipse.rdf4j.model.*;
@@ -32,6 +31,7 @@
3231
import org.eclipse.rdf4j.repository.Repository;
3332
import org.eclipse.rdf4j.repository.RepositoryConnection;
3433
import org.eclipse.rdf4j.repository.RepositoryException;
34+
import org.jspecify.annotations.Nullable;
3535

3636
import java.util.*;
3737

0 commit comments

Comments
 (0)