Skip to content

Commit fed52b2

Browse files
authored
upgrade jackson dependency 2.11.1 -> 2.20 (#33)
* upgraded Jackson dependencies and registered JdkModule with ObjectMapper so that Optional fields can be serialised
1 parent 09d043b commit fed52b2

5 files changed

Lines changed: 37 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Significant changes since 0.1.0
22

3+
1.4.0 2026-02-19
4+
5+
- feature: upgraded Jackson dependencies and registered JdkModule with ObjectMapper so that Optional fields can be serialised
6+
37
1.3.0 2025-12-01
48

59
- feature: added 'license' field to DatasetFacade/DatasetVersion #32

build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ apply plugin: 'java'
22

33
group = 'com.researchspace'
44
sourceCompatibility = 1.8
5-
version = '1.3.0'
5+
version = '1.4.0'
66
def springVersion='5.3.24'
7-
def jacksonVersion='2.11.1'
7+
def jacksonVersion='2.20.0'
8+
def jacksonAnnotationsVersion='2.20'
89
def lombokVersion='1.18.24'
910

1011
repositories {
@@ -41,9 +42,11 @@ dependencies {
4142
implementation 'org.springframework:spring-web:'+springVersion
4243
implementation 'org.springframework:spring-context:'+springVersion
4344
implementation 'org.springframework:spring-core:'+springVersion
44-
implementation 'com.fasterxml.jackson.core:jackson-annotations:'+jacksonVersion
45+
implementation 'com.fasterxml.jackson.core:jackson-annotations:'+jacksonAnnotationsVersion
4546
implementation 'com.fasterxml.jackson.core:jackson-core:'+jacksonVersion
4647
implementation 'com.fasterxml.jackson.core:jackson-databind:'+jacksonVersion
48+
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:'+jacksonVersion
49+
4750

4851
implementation 'org.projectlombok:lombok:' + lombokVersion
4952
annotationProcessor 'org.projectlombok:lombok:' + lombokVersion

src/main/java/com/researchspace/dataverse/http/DataverseOperationsImplV1.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.fasterxml.jackson.core.JsonProcessingException;
77
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
89
import com.researchspace.dataverse.api.v1.DatasetOperations;
910
import com.researchspace.dataverse.api.v1.DataverseOperations;
1011
import com.researchspace.dataverse.api.v1.InfoOperations;
@@ -290,14 +291,14 @@ private String getJsonFromFacade(DatasetFacade facade) {
290291

291292
private String marshalDataset(Object object) {
292293
ObjectMapper mapper = new ObjectMapper();
294+
mapper.registerModule(new Jdk8Module());
293295
String json = "";
294-
try {
295-
json = mapper.writeValueAsString(object);
296-
} catch (JsonProcessingException e) {
297-
// TODO Auto-generated catch block
298-
e.printStackTrace();
299-
}
300-
return json;
296+
try {
297+
json = mapper.writeValueAsString(object);
298+
} catch (JsonProcessingException e) {
299+
throw new RuntimeException(e);
300+
}
301+
return json;
301302
}
302303

303304
/* (non-Javadoc)

src/test/java/com/researchspace/dataverse/entities/DatasetTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import static org.junit.Assert.assertEquals;
77
import static org.junit.Assert.assertFalse;
88

9+
import com.fasterxml.jackson.databind.ObjectMapper;
10+
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
11+
import java.io.IOException;
912
import java.net.MalformedURLException;
1013
import java.net.URL;
11-
1214
import org.junit.After;
1315
import org.junit.Before;
1416
import org.junit.Test;
@@ -48,5 +50,16 @@ public void GetDoiId() throws MalformedURLException {
4850
ds.setPersistentUrl(new URL(EXAMPLE_DOI_URL));
4951
assertEquals(EXPECTED_DOI_ID, ds.getDoiId().get());
5052
}
53+
@Test
54+
public void testJacksonBehaviour() throws IOException {
55+
Dataset dataverseDataset = new Dataset();
56+
dataverseDataset.setId(1L);
57+
dataverseDataset.setPersistentUrl(new URL("http://localhost:8080/api/datasets/1/versions/1.1"));
58+
ObjectMapper objectMapper = new ObjectMapper();
59+
objectMapper.registerModule(new Jdk8Module());
60+
String json = "";
61+
json = objectMapper.writeValueAsString(dataverseDataset);
62+
System.out.println(json);
63+
}
5164

5265
}

src/test/java/com/researchspace/dataverse/entities/facade/DatasetBuilderTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import static com.researchspace.dataverse.entities.facade.DatasetTestFactory.*;
77

8+
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
89
import java.net.MalformedURLException;
910
import java.net.URISyntaxException;
1011

@@ -49,9 +50,11 @@ public void tearDown() throws Exception {
4950
@Test
5051
public void test() throws JsonProcessingException, MalformedURLException, URISyntaxException {
5152
DatasetFacade facade = createFacade();
52-
ObjectWriter mapper = new ObjectMapper().writerWithDefaultPrettyPrinter();
53+
ObjectMapper mapper = new ObjectMapper();
54+
mapper.registerModule(new Jdk8Module());
55+
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
5356
Dataset dversion = builder.build(facade);
54-
String json = mapper.writeValueAsString(dversion);
57+
String json = ow.writeValueAsString(dversion);
5558
System.out.println(json);
5659
}
5760
}

0 commit comments

Comments
 (0)