Skip to content

Commit 95c6a8d

Browse files
committed
GH-5723: migrate rdf4j-sail-nativerdf to Jackson 3.1.2
- Update jackson-core dependency to tools.jackson.core groupId - Update imports to tools.jackson.core.* / tools.jackson.core.json.JsonFactory - JsonToken.FIELD_NAME → JsonToken.PROPERTY_NAME - JsonParser: getCurrentName() → currentName() - JsonGenerator: writeStringField/writeNumberField/writeObjectFieldStart → writeStringProperty/writeNumberProperty/writeObjectPropertyStart - Replace deprecated createParser(byte[]) with createParser(ObjectReadContext.empty(), content) - Replace deprecated createGenerator(OutputStream) with createGenerator(ObjectWriteContext.empty(), out)
1 parent 4762247 commit 95c6a8d

23 files changed

Lines changed: 329 additions & 304 deletions

core/sail/nativerdf/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@
4747
<version>${project.version}</version>
4848
</dependency>
4949
<dependency>
50-
<groupId>com.fasterxml.jackson.core</groupId>
50+
<groupId>tools.jackson.core</groupId>
5151
<artifactId>jackson-core</artifactId>
52+
<version>${jackson3.version}</version>
5253
</dependency>
5354
<dependency>
5455
<groupId>org.slf4j</groupId>

core/sail/nativerdf/src/main/java/org/eclipse/rdf4j/sail/nativerdf/wal/ValueStoreWAL.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@
4242
import org.slf4j.Logger;
4343
import org.slf4j.LoggerFactory;
4444

45-
import com.fasterxml.jackson.core.JsonFactory;
46-
import com.fasterxml.jackson.core.JsonGenerator;
47-
import com.fasterxml.jackson.core.JsonParser;
48-
import com.fasterxml.jackson.core.JsonToken;
45+
import tools.jackson.core.JsonGenerator;
46+
import tools.jackson.core.JsonParser;
47+
import tools.jackson.core.JsonToken;
48+
import tools.jackson.core.ObjectReadContext;
49+
import tools.jackson.core.ObjectWriteContext;
50+
import tools.jackson.core.json.JsonFactory;
4951

5052
/**
5153
* Write-ahead log (WAL) for the ValueStore. The WAL records minted values in append-only segments so they can be
@@ -401,10 +403,10 @@ static int readSegmentSequence(Path path) throws IOException {
401403
// skip CRC
402404
in.readNBytes(4);
403405
JsonFactory factory = new JsonFactory();
404-
try (JsonParser parser = factory.createParser(jsonBytes)) {
406+
try (JsonParser parser = factory.createParser(ObjectReadContext.empty(), jsonBytes)) {
405407
while (parser.nextToken() != JsonToken.END_OBJECT) {
406-
if (parser.currentToken() == JsonToken.FIELD_NAME) {
407-
String field = parser.getCurrentName();
408+
if (parser.currentToken() == JsonToken.PROPERTY_NAME) {
409+
String field = parser.currentName();
408410
parser.nextToken();
409411
if ("segment".equals(field)) {
410412
return parser.getIntValue();
@@ -823,11 +825,11 @@ private void gzipAndDelete(Path src, int lastMintedId) {
823825
private byte[] buildSummaryFrame(int lastMintedId, long crc32Value) throws IOException {
824826
JsonFactory factory = new JsonFactory();
825827
ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
826-
try (JsonGenerator gen = factory.createGenerator(baos)) {
828+
try (JsonGenerator gen = factory.createGenerator(ObjectWriteContext.empty(), baos)) {
827829
gen.writeStartObject();
828-
gen.writeStringField("t", "S");
829-
gen.writeNumberField("lastId", lastMintedId);
830-
gen.writeNumberField("crc32", crc32Value & 0xFFFFFFFFL);
830+
gen.writeStringProperty("t", "S");
831+
gen.writeNumberProperty("lastId", lastMintedId);
832+
gen.writeNumberProperty("crc32", crc32Value & 0xFFFFFFFFL);
831833
gen.writeEndObject();
832834
}
833835
baos.write('\n');
@@ -846,15 +848,15 @@ private byte[] buildSummaryFrame(int lastMintedId, long crc32Value) throws IOExc
846848
private void writeHeader(int firstId) throws IOException {
847849
JsonFactory factory = new JsonFactory();
848850
ByteArrayOutputStream baos = new ByteArrayOutputStream(256);
849-
try (JsonGenerator gen = factory.createGenerator(baos)) {
851+
try (JsonGenerator gen = factory.createGenerator(ObjectWriteContext.empty(), baos)) {
850852
gen.writeStartObject();
851-
gen.writeStringField("t", "V");
852-
gen.writeNumberField("ver", 1);
853-
gen.writeStringField("store", config.storeUuid());
854-
gen.writeStringField("engine", "valuestore");
855-
gen.writeNumberField("created", Instant.now().getEpochSecond());
856-
gen.writeNumberField("segment", segmentSequence);
857-
gen.writeNumberField("firstId", firstId);
853+
gen.writeStringProperty("t", "V");
854+
gen.writeNumberProperty("ver", 1);
855+
gen.writeStringProperty("store", config.storeUuid());
856+
gen.writeStringProperty("engine", "valuestore");
857+
gen.writeNumberProperty("created", Instant.now().getEpochSecond());
858+
gen.writeNumberProperty("segment", segmentSequence);
859+
gen.writeNumberProperty("firstId", firstId);
858860
gen.writeEndObject();
859861
}
860862
// NDJSON: newline-delimited JSON
@@ -884,16 +886,16 @@ private int checksum(byte[] data, int len) {
884886

885887
private int encodeIntoReusableBuffer(ValueStoreWalRecord record) throws IOException {
886888
jsonBuffer.reset();
887-
try (JsonGenerator gen = jsonFactory.createGenerator(jsonBuffer)) {
889+
try (JsonGenerator gen = jsonFactory.createGenerator(ObjectWriteContext.empty(), jsonBuffer)) {
888890
gen.writeStartObject();
889-
gen.writeStringField("t", "M");
890-
gen.writeNumberField("lsn", record.lsn());
891-
gen.writeNumberField("id", record.id());
892-
gen.writeStringField("vk", String.valueOf(record.valueKind().code()));
893-
gen.writeStringField("lex", record.lexical() == null ? "" : record.lexical());
894-
gen.writeStringField("dt", record.datatype() == null ? "" : record.datatype());
895-
gen.writeStringField("lang", record.language() == null ? "" : record.language());
896-
gen.writeNumberField("hash", record.hash());
891+
gen.writeStringProperty("t", "M");
892+
gen.writeNumberProperty("lsn", record.lsn());
893+
gen.writeNumberProperty("id", record.id());
894+
gen.writeStringProperty("vk", String.valueOf(record.valueKind().code()));
895+
gen.writeStringProperty("lex", record.lexical() == null ? "" : record.lexical());
896+
gen.writeStringProperty("dt", record.datatype() == null ? "" : record.datatype());
897+
gen.writeStringProperty("lang", record.language() == null ? "" : record.language());
898+
gen.writeNumberProperty("hash", record.hash());
897899
gen.writeEndObject();
898900
}
899901
jsonBuffer.write('\n'); // NDJSON newline

core/sail/nativerdf/src/main/java/org/eclipse/rdf4j/sail/nativerdf/wal/ValueStoreWalReader.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
import org.slf4j.Logger;
3333
import org.slf4j.LoggerFactory;
3434

35-
import com.fasterxml.jackson.core.JsonFactory;
36-
import com.fasterxml.jackson.core.JsonParser;
37-
import com.fasterxml.jackson.core.JsonToken;
38-
import com.fasterxml.jackson.core.StreamReadConstraints;
35+
import tools.jackson.core.JsonParser;
36+
import tools.jackson.core.JsonToken;
37+
import tools.jackson.core.ObjectReadContext;
38+
import tools.jackson.core.StreamReadConstraints;
39+
import tools.jackson.core.json.JsonFactory;
3940

4041
/**
4142
* Reader for ValueStore WAL segments that yields minted records in LSN order across segments. It tolerates truncated or
@@ -419,12 +420,12 @@ private void prepareNext() throws IOException {
419420

420421
private Parsed parseJson(byte[] jsonBytes) throws IOException {
421422
Parsed parsed = new Parsed();
422-
try (JsonParser jp = jsonFactory.createParser(jsonBytes)) {
423+
try (JsonParser jp = jsonFactory.createParser(ObjectReadContext.empty(), jsonBytes)) {
423424
if (jp.nextToken() != JsonToken.START_OBJECT) {
424425
return parsed;
425426
}
426427
while (jp.nextToken() != JsonToken.END_OBJECT) {
427-
String field = jp.getCurrentName();
428+
String field = jp.currentName();
428429
jp.nextToken();
429430
if ("t".equals(field)) {
430431
String t = jp.getValueAsString("");

core/sail/nativerdf/src/main/java/org/eclipse/rdf4j/sail/nativerdf/wal/ValueStoreWalSearch.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
import org.eclipse.rdf4j.model.Value;
3232
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
3333

34-
import com.fasterxml.jackson.core.JsonFactory;
35-
import com.fasterxml.jackson.core.JsonParser;
36-
import com.fasterxml.jackson.core.JsonToken;
37-
import com.fasterxml.jackson.core.StreamReadConstraints;
34+
import tools.jackson.core.JsonParser;
35+
import tools.jackson.core.JsonToken;
36+
import tools.jackson.core.ObjectReadContext;
37+
import tools.jackson.core.StreamReadConstraints;
38+
import tools.jackson.core.json.JsonFactory;
3839

3940
/**
4041
* Utility to search a ValueStore WAL for a specific minted value ID efficiently.
@@ -267,12 +268,12 @@ private int readIntLE(InputStream in) throws IOException {
267268

268269
private Parsed parseJson(byte[] jsonBytes) throws IOException {
269270
Parsed parsed = new Parsed();
270-
try (JsonParser jp = jsonFactory.createParser(jsonBytes)) {
271+
try (JsonParser jp = jsonFactory.createParser(ObjectReadContext.empty(), jsonBytes)) {
271272
if (jp.nextToken() != JsonToken.START_OBJECT) {
272273
return parsed;
273274
}
274275
while (jp.nextToken() != JsonToken.END_OBJECT) {
275-
String field = jp.getCurrentName();
276+
String field = jp.currentName();
276277
jp.nextToken();
277278
if ("t".equals(field)) {
278279
String t = jp.getValueAsString("");

core/sail/nativerdf/src/test/java/org/eclipse/rdf4j/sail/nativerdf/ValueStoreRandomLookupTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@
5858
import org.junit.jupiter.api.Test;
5959
import org.junit.jupiter.api.io.TempDir;
6060

61-
import com.fasterxml.jackson.core.JsonFactory;
62-
import com.fasterxml.jackson.core.JsonParser;
63-
import com.fasterxml.jackson.core.JsonToken;
61+
import tools.jackson.core.JsonParser;
62+
import tools.jackson.core.JsonToken;
63+
import tools.jackson.core.ObjectReadContext;
64+
import tools.jackson.core.json.JsonFactory;
6465

6566
class ValueStoreRandomLookupTest {
6667

@@ -331,16 +332,16 @@ private static final class ParsedRecord {
331332
}
332333

333334
static ParsedRecord parse(byte[] json) throws IOException {
334-
try (JsonParser parser = JSON_FACTORY.createParser(json)) {
335+
try (JsonParser parser = JSON_FACTORY.createParser(ObjectReadContext.empty(), json)) {
335336
char type = '?';
336337
int id = 0;
337338
long crc32 = 0L;
338339
ValueStoreWalValueKind kind = ValueStoreWalValueKind.NAMESPACE;
339340
int segment = 0;
340341
while (parser.nextToken() != null) {
341342
JsonToken token = parser.currentToken();
342-
if (token == JsonToken.FIELD_NAME) {
343-
String field = parser.getCurrentName();
343+
if (token == JsonToken.PROPERTY_NAME) {
344+
String field = parser.currentName();
344345
parser.nextToken();
345346
if ("t".equals(field)) {
346347
String value = parser.getValueAsString("");

core/sail/nativerdf/src/test/java/org/eclipse/rdf4j/sail/nativerdf/wal/ValueStoreWALReadSegmentSequenceEdgeCasesTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
import org.junit.jupiter.api.Test;
2424
import org.junit.jupiter.api.io.TempDir;
2525

26-
import com.fasterxml.jackson.core.JsonFactory;
27-
import com.fasterxml.jackson.core.JsonGenerator;
26+
import tools.jackson.core.JsonGenerator;
27+
import tools.jackson.core.ObjectWriteContext;
28+
import tools.jackson.core.json.JsonFactory;
2829

2930
@Tag("slow")
3031
class ValueStoreWALReadSegmentSequenceEdgeCasesTest {
@@ -76,14 +77,14 @@ void returnsZeroWhenHeaderHasNoSegmentField() throws Exception {
7677
private static byte[] headerWithoutSegment() throws IOException {
7778
JsonFactory f = new JsonFactory();
7879
ByteArrayOutputStream baos = new ByteArrayOutputStream();
79-
try (JsonGenerator g = f.createGenerator(baos)) {
80+
try (JsonGenerator g = f.createGenerator(ObjectWriteContext.empty(), baos)) {
8081
g.writeStartObject();
81-
g.writeStringField("t", "V");
82-
g.writeNumberField("ver", 1);
83-
g.writeStringField("store", "s");
84-
g.writeStringField("engine", "valuestore");
85-
g.writeNumberField("created", 0);
86-
g.writeNumberField("firstId", 1);
82+
g.writeStringProperty("t", "V");
83+
g.writeNumberProperty("ver", 1);
84+
g.writeStringProperty("store", "s");
85+
g.writeStringProperty("engine", "valuestore");
86+
g.writeNumberProperty("created", 0);
87+
g.writeNumberProperty("firstId", 1);
8788
g.writeEndObject();
8889
}
8990
baos.write('\n');

core/sail/nativerdf/src/test/java/org/eclipse/rdf4j/sail/nativerdf/wal/ValueStoreWalCompressedNoSummaryTest.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
import org.junit.jupiter.api.Test;
2626
import org.junit.jupiter.api.io.TempDir;
2727

28-
import com.fasterxml.jackson.core.JsonFactory;
29-
import com.fasterxml.jackson.core.JsonGenerator;
28+
import tools.jackson.core.JsonGenerator;
29+
import tools.jackson.core.ObjectWriteContext;
30+
import tools.jackson.core.json.JsonFactory;
3031

3132
/**
3233
* Validates that a compressed segment lacking a summary frame results in incomplete scan.
@@ -75,15 +76,15 @@ private static void frame(GZIPOutputStream out, byte[] json) throws IOException
7576
private static byte[] headerJson(int segment, int firstId) throws IOException {
7677
JsonFactory f = new JsonFactory();
7778
ByteArrayOutputStream baos = new ByteArrayOutputStream();
78-
try (JsonGenerator g = f.createGenerator(baos)) {
79+
try (JsonGenerator g = f.createGenerator(ObjectWriteContext.empty(), baos)) {
7980
g.writeStartObject();
80-
g.writeStringField("t", "V");
81-
g.writeNumberField("ver", 1);
82-
g.writeStringField("store", "s");
83-
g.writeStringField("engine", "valuestore");
84-
g.writeNumberField("created", 0);
85-
g.writeNumberField("segment", segment);
86-
g.writeNumberField("firstId", firstId);
81+
g.writeStringProperty("t", "V");
82+
g.writeNumberProperty("ver", 1);
83+
g.writeStringProperty("store", "s");
84+
g.writeStringProperty("engine", "valuestore");
85+
g.writeNumberProperty("created", 0);
86+
g.writeNumberProperty("segment", segment);
87+
g.writeNumberProperty("firstId", firstId);
8788
g.writeEndObject();
8889
}
8990
baos.write('\n');
@@ -93,16 +94,16 @@ private static byte[] headerJson(int segment, int firstId) throws IOException {
9394
private static byte[] mintedJson(long lsn, int id) throws IOException {
9495
JsonFactory f = new JsonFactory();
9596
ByteArrayOutputStream baos = new ByteArrayOutputStream();
96-
try (JsonGenerator g = f.createGenerator(baos)) {
97+
try (JsonGenerator g = f.createGenerator(ObjectWriteContext.empty(), baos)) {
9798
g.writeStartObject();
98-
g.writeStringField("t", "M");
99-
g.writeNumberField("lsn", lsn);
100-
g.writeNumberField("id", id);
101-
g.writeStringField("vk", "I");
102-
g.writeStringField("lex", "http://ex/id" + id);
103-
g.writeStringField("dt", "");
104-
g.writeStringField("lang", "");
105-
g.writeNumberField("hash", 0);
99+
g.writeStringProperty("t", "M");
100+
g.writeNumberProperty("lsn", lsn);
101+
g.writeNumberProperty("id", id);
102+
g.writeStringProperty("vk", "I");
103+
g.writeStringProperty("lex", "http://ex/id" + id);
104+
g.writeStringProperty("dt", "");
105+
g.writeStringProperty("lang", "");
106+
g.writeNumberProperty("hash", 0);
106107
g.writeEndObject();
107108
}
108109
baos.write('\n');

core/sail/nativerdf/src/test/java/org/eclipse/rdf4j/sail/nativerdf/wal/ValueStoreWalCompressedSegmentRestoreTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
import org.junit.jupiter.api.Test;
3434
import org.junit.jupiter.api.io.TempDir;
3535

36-
import com.fasterxml.jackson.core.JsonFactory;
37-
import com.fasterxml.jackson.core.JsonParser;
38-
import com.fasterxml.jackson.core.JsonToken;
36+
import tools.jackson.core.JsonParser;
37+
import tools.jackson.core.JsonToken;
38+
import tools.jackson.core.ObjectReadContext;
39+
import tools.jackson.core.json.JsonFactory;
3940

4041
/**
4142
* Restores a value record from a compressed ValueStore WAL segment by performing a binary search on segment first LSNs.
@@ -219,12 +220,12 @@ private static int readIntLE(InputStream in) throws IOException {
219220

220221
private static Parsed parseJson(byte[] jsonBytes) throws IOException {
221222
Parsed parsed = new Parsed();
222-
try (JsonParser jp = JSON_FACTORY.createParser(jsonBytes)) {
223+
try (JsonParser jp = JSON_FACTORY.createParser(ObjectReadContext.empty(), jsonBytes)) {
223224
if (jp.nextToken() != JsonToken.START_OBJECT) {
224225
return parsed;
225226
}
226227
while (jp.nextToken() != JsonToken.END_OBJECT) {
227-
String field = jp.getCurrentName();
228+
String field = jp.currentName();
228229
jp.nextToken();
229230
if ("t".equals(field)) {
230231
String t = jp.getValueAsString("");

core/sail/nativerdf/src/test/java/org/eclipse/rdf4j/sail/nativerdf/wal/ValueStoreWalCompressedSummaryCrcValidationTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
import org.junit.jupiter.api.Test;
3131
import org.junit.jupiter.api.io.TempDir;
3232

33-
import com.fasterxml.jackson.core.JsonFactory;
34-
import com.fasterxml.jackson.core.JsonGenerator;
35-
import com.fasterxml.jackson.core.JsonParser;
36-
import com.fasterxml.jackson.core.JsonToken;
33+
import tools.jackson.core.JsonGenerator;
34+
import tools.jackson.core.JsonParser;
35+
import tools.jackson.core.JsonToken;
36+
import tools.jackson.core.ObjectReadContext;
37+
import tools.jackson.core.ObjectWriteContext;
38+
import tools.jackson.core.json.JsonFactory;
3739

3840
/**
3941
* Validates that ValueStoreWalReader verifies the CRC32 summary embedded in compressed segments and marks the scan as
@@ -119,14 +121,14 @@ private static void corruptSummaryCrc32(Path gz) throws IOException {
119121
pos += 4;
120122

121123
// Parse JSON and detect summary frame
122-
try (JsonParser jp = new JsonFactory().createParser(json)) {
124+
try (JsonParser jp = new JsonFactory().createParser(ObjectReadContext.empty(), json)) {
123125
if (jp.nextToken() != JsonToken.START_OBJECT) {
124126
continue;
125127
}
126128
String type = null;
127129
Integer lid = null;
128130
while (jp.nextToken() != JsonToken.END_OBJECT) {
129-
String field = jp.getCurrentName();
131+
String field = jp.currentName();
130132
jp.nextToken();
131133
if ("t".equals(field)) {
132134
type = jp.getValueAsString("");
@@ -166,11 +168,11 @@ private static void corruptSummaryCrc32(Path gz) throws IOException {
166168
private static byte[] buildSummaryFrameWithCrc(int lastMintedId, long wrongCrc32) throws IOException {
167169
JsonFactory factory = new JsonFactory();
168170
ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
169-
try (JsonGenerator gen = factory.createGenerator(baos)) {
171+
try (JsonGenerator gen = factory.createGenerator(ObjectWriteContext.empty(), baos)) {
170172
gen.writeStartObject();
171-
gen.writeStringField("t", "S");
172-
gen.writeNumberField("lastId", lastMintedId);
173-
gen.writeNumberField("crc32", wrongCrc32 & 0xFFFFFFFFL);
173+
gen.writeStringProperty("t", "S");
174+
gen.writeNumberProperty("lastId", lastMintedId);
175+
gen.writeNumberProperty("crc32", wrongCrc32 & 0xFFFFFFFFL);
174176
gen.writeEndObject();
175177
}
176178
baos.write('\n');

0 commit comments

Comments
 (0)