Skip to content

Commit ae8bcba

Browse files
committed
GH-5744: Migrate rdf4j-query to Jackson 3.1.x
- Removed JsonProcessingException import (now JacksonException, unchecked — no longer needed) - Added JsonMapper import (tools.jackson.databind.json.JsonMapper) - Replaced mutable new ObjectMapper() + chained setters with an immutable JsonMapper.builder() configured via changeDefaultVisibility() and changeDefaultPropertyInclusion() - Removed try/catch in toJson() since Jackson 3 exceptions are unchecked
1 parent d2faa95 commit ae8bcba

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

core/query/pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
<artifactId>jackson-annotations</artifactId>
2626
</dependency>
2727
<dependency>
28-
<groupId>com.fasterxml.jackson.core</groupId>
28+
<groupId>tools.jackson.core</groupId>
2929
<artifactId>jackson-core</artifactId>
30+
<version>${jackson3.version}</version>
3031
</dependency>
3132
<dependency>
32-
<groupId>com.fasterxml.jackson.core</groupId>
33+
<groupId>tools.jackson.core</groupId>
3334
<artifactId>jackson-databind</artifactId>
35+
<version>${jackson3.version}</version>
3436
</dependency>
3537
<dependency>
3638
<groupId>org.apache.commons</groupId>

core/query/src/main/java/org/eclipse/rdf4j/query/explanation/ExplanationImpl.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
import com.fasterxml.jackson.annotation.JsonAutoDetect;
1616
import com.fasterxml.jackson.annotation.JsonInclude;
1717
import com.fasterxml.jackson.annotation.PropertyAccessor;
18-
import com.fasterxml.jackson.core.JsonProcessingException;
19-
import com.fasterxml.jackson.databind.ObjectMapper;
18+
19+
import tools.jackson.databind.ObjectMapper;
20+
import tools.jackson.databind.json.JsonMapper;
2021

2122
/**
2223
* This is an experimental feature. It may be changed, moved or potentially removed in a future release.
@@ -37,7 +38,12 @@ public ExplanationImpl(GenericPlanNode genericPlanNode, boolean timedOut, Object
3738
}
3839
}
3940

40-
ObjectMapper objectMapper = new ObjectMapper();
41+
ObjectMapper objectMapper = JsonMapper.builder()
42+
.changeDefaultVisibility(vc -> vc
43+
.withVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.PUBLIC_ONLY)
44+
.withVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NONE))
45+
.changeDefaultPropertyInclusion(incl -> incl.withValueInclusion(JsonInclude.Include.NON_NULL))
46+
.build();
4147

4248
@Override
4349
public Object tupleExpr() {
@@ -51,16 +57,10 @@ public GenericPlanNode toGenericPlanNode() {
5157

5258
@Override
5359
public String toJson() {
54-
try {
55-
// TODO: Consider removing pretty printer
56-
return this.objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.PUBLIC_ONLY)
57-
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NONE)
58-
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
59-
.writerWithDefaultPrettyPrinter()
60-
.writeValueAsString(toGenericPlanNode());
61-
} catch (JsonProcessingException e) {
62-
throw new RuntimeException(e);
63-
}
60+
// TODO: Consider removing pretty printer
61+
return this.objectMapper
62+
.writerWithDefaultPrettyPrinter()
63+
.writeValueAsString(toGenericPlanNode());
6464
}
6565

6666
@Override

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<httpcore5.version>5.3.4</httpcore5.version>
6464
<jackson.version>2.21.0</jackson.version>
6565
<jackson.annotations.version>2.21</jackson.annotations.version>
66+
<jackson3.version>3.1.2</jackson3.version>
6667
<httpcore.version>4.4.16</httpcore.version>
6768
<jsonldjava.version>0.13.4</jsonldjava.version>
6869
<last.japicmp.compare.version>6.0.0</last.japicmp.compare.version>

0 commit comments

Comments
 (0)