Skip to content

Commit 29bdb09

Browse files
Siedlerchrkoppor
andauthored
Convert to jackson 3 (#14259)
* convert to jackson 3 * checkstyle * checkstyle * fix jbang and checkstlye * fix typo * fix jbang * fix jbang * fix jbang * fix jbang * fix artifat id * add jackson annotations * fix imports * fix imports * Add debug * fix imports * add jackson deps to jbang * fix import * fix imports * reveRT CSL CHANGE * fix imports * add to example * cahnge mscocde utils * fix lsp import * ad jackson annotaitons * ad jackson annotaitons * Try to fix .. * Fix variable --------- Co-authored-by: Oliver Kopp <[email protected]>
1 parent 6ebda27 commit 29bdb09

File tree

15 files changed

+61
-42
lines changed

15 files changed

+61
-42
lines changed

.github/workflows/tests-code.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ jobs:
576576
echo "//SOURCES ../../$f" >> "${{ matrix.script }}"
577577
fi
578578
done
579+
- run: cat ${{ matrix.script }}
579580
- run: jbang build "${{ matrix.script }}"
580581
shell: bash
581582
- run: jbang "${{ matrix.script }}" --help

.jbang/JabLsLauncher.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
//DEPS org.jspecify:jspecify:1.0.0
3737

3838
// from jabls
39-
//DEPS com.fasterxml.jackson.core:jackson-databind:2.20.1
39+
//DEPS com.fasterxml.jackson.core:jackson-annotations:2.20
40+
//DEPS tools.jackson.core:jackson-core:3.0.2
41+
//DEPS tools.jackson.core:jackson-databind:3.0.2
42+
//DEPS tools.jackson.dataformat:jackson-dataformat-yaml:3.0.2
4043
//DEPS info.picocli:picocli:4.7.7
4144
//DEPS org.apache.logging.log4j:log4j-to-slf4j:2.25.2
4245
//DEPS org.eclipse.lsp4j:org.eclipse.lsp4j:0.24.0

.jbang/JabSrvLauncher.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@
7979
//DEPS org.jabref:afterburner.fx:2.0.0
8080
//DEPS net.harawata:appdirs:1.5.0
8181
//DEPS de.undercouch:citeproc-java:3.4.0
82-
//DEPS com.github.ben-manes.caffeine:caffeine:3.2.3
82+
//DEPS com.github.ben-manes.caffeine:caffeine:3.2.3
83+
//DEPS tools.jackson.core:jackson-core:3.0.2
84+
//DEPS tools.jackson.core:jackson-databind:3.0.2
85+
//DEPS tools.jackson.dataformat:jackson-dataformat-yaml:3.0.2
8386
//DEPS org.apache.commons:commons-lang3:3.20.0
8487

8588
/// This class is required for [jbang](https://www.jbang.dev/)

jablib-examples/jbang/ieee_pdf_references_to_bibtex.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
//DEPS org.jabref:jablib:6.0-SNAPSHOT
1919
// JabRef relies on PR https://github.com/unicode-org/icu/pull/2127; for experiments the release version is OK.
2020
//DEPS com.ibm.icu:icu4j:78.1
21+
//DEPS com.fasterxml.jackson.core:jackson-annotations:2.20
22+
//DEPS tools.jackson.core:jackson-core:3.0.2
23+
//DEPS tools.jackson.core:jackson-databind:3.0.2
24+
//DEPS tools.jackson.dataformat:jackson-dataformat-yaml:3.0.2
2125

2226
void main() throws Exception {
2327
var preferences = JabRefCliPreferences.getInstance();

jablib/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ dependencies {
103103

104104
implementation("org.eclipse.jgit:org.eclipse.jgit")
105105

106-
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
107-
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
106+
implementation("tools.jackson.dataformat:jackson-dataformat-yaml")
107+
implementation("tools.jackson.core:jackson-databind")
108108
// TODO: Somwewhere we get a warning: unknown enum constant Id.CLASS reason: class file for com.fasterxml.jackson.annotation.JsonTypeInfo$Id not found
109109
// implementation("com.fasterxml.jackson.core:jackson-annotations:2.19.1")
110110

jablib/src/main/java/module-info.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@
155155
// region: data mapping
156156
requires jdk.xml.dom;
157157
requires com.google.gson;
158-
requires com.fasterxml.jackson.databind;
159-
requires com.fasterxml.jackson.dataformat.yaml;
160-
requires com.fasterxml.jackson.datatype.jsr310;
158+
requires tools.jackson.databind;
159+
requires tools.jackson.dataformat.yaml;
160+
requires tools.jackson.core;
161161
// endregion
162162

163163
// region HTTP clients

jablib/src/main/java/org/jabref/logic/citationstyle/CSLStyleLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
import org.jabref.logic.openoffice.OpenOfficePreferences;
1111

12-
import com.fasterxml.jackson.core.type.TypeReference;
13-
import com.fasterxml.jackson.databind.ObjectMapper;
1412
import org.jspecify.annotations.NonNull;
1513
import org.jspecify.annotations.Nullable;
1614
import org.slf4j.Logger;
1715
import org.slf4j.LoggerFactory;
16+
import tools.jackson.core.type.TypeReference;
17+
import tools.jackson.databind.ObjectMapper;
1818

1919
/**
2020
* Manages the loading of CitationStyles from both internal resources and external files.

jablib/src/main/java/org/jabref/logic/crawler/StudyYamlParser.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
import org.jabref.model.study.Study;
99

10-
import com.fasterxml.jackson.databind.ObjectMapper;
11-
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
12-
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
10+
import tools.jackson.databind.ObjectMapper;
11+
import tools.jackson.dataformat.yaml.YAMLFactory;
12+
import tools.jackson.dataformat.yaml.YAMLMapper;
13+
import tools.jackson.dataformat.yaml.YAMLWriteFeature;
1314

1415
/**
1516
* Example use: <code>new StudyYamlParser().parseStudyYamlFile(studyDefinitionFile);</code>
@@ -30,8 +31,10 @@ public Study parseStudyYamlFile(Path studyYamlFile) throws IOException {
3031
* Writes the given study instance into a yaml file to the given path
3132
*/
3233
public void writeStudyYamlFile(Study study, Path studyYamlFile) throws IOException {
33-
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
34-
.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES));
34+
35+
ObjectMapper yamlMapper = new YAMLMapper(YAMLFactory.builder()
36+
.disable(YAMLWriteFeature.WRITE_DOC_START_MARKER)
37+
.enable(YAMLWriteFeature.MINIMIZE_QUOTES).build());
3538
yamlMapper.writeValue(studyYamlFile.toFile(), study);
3639
}
3740
}

jablib/src/main/java/org/jabref/logic/importer/fileformat/CffImporter.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626

2727
import com.fasterxml.jackson.annotation.JsonAnySetter;
2828
import com.fasterxml.jackson.annotation.JsonProperty;
29-
import com.fasterxml.jackson.databind.ObjectMapper;
30-
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
3129
import com.google.common.collect.HashBiMap;
3230
import org.jspecify.annotations.NonNull;
31+
import tools.jackson.core.JacksonException;
32+
import tools.jackson.databind.ObjectMapper;
33+
import tools.jackson.dataformat.yaml.YAMLFactory;
34+
import tools.jackson.dataformat.yaml.YAMLMapper;
3335

3436
public class CffImporter extends Importer {
3537

@@ -171,7 +173,7 @@ private void setValues(String key, String value) {
171173

172174
@Override
173175
public ParserResult importDatabase(@NonNull BufferedReader reader) throws IOException {
174-
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
176+
ObjectMapper mapper = new YAMLMapper(new YAMLFactory());
175177
CffFormat citation = mapper.readValue(reader, CffFormat.class);
176178
List<BibEntry> entriesList = new ArrayList<>();
177179

@@ -263,14 +265,13 @@ public ParserResult importDatabase(@NonNull BufferedReader reader) throws IOExce
263265

264266
@Override
265267
public boolean isRecognizedFormat(@NonNull BufferedReader reader) throws IOException {
266-
267-
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
268+
ObjectMapper mapper = new YAMLMapper(new YAMLFactory());
268269
CffFormat citation;
269270

270271
try {
271272
citation = mapper.readValue(reader, CffFormat.class);
272273
return (citation != null) && (citation.values.get("title") != null);
273-
} catch (IOException e) {
274+
} catch (JacksonException e) {
274275
return false;
275276
}
276277
}

jablib/src/main/java/org/jabref/logic/util/MscCodeUtils.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
import org.jabref.logic.shared.exception.MscCodeLoadingException;
99

10-
import com.fasterxml.jackson.core.JsonParseException;
11-
import com.fasterxml.jackson.core.type.TypeReference;
12-
import com.fasterxml.jackson.databind.JsonMappingException;
13-
import com.fasterxml.jackson.databind.ObjectMapper;
1410
import com.google.common.collect.HashBiMap;
1511
import org.jspecify.annotations.NonNull;
1612
import org.slf4j.Logger;
1713
import org.slf4j.LoggerFactory;
14+
import tools.jackson.core.exc.StreamReadException;
15+
import tools.jackson.core.type.TypeReference;
16+
import tools.jackson.databind.DatabindException;
17+
import tools.jackson.databind.ObjectMapper;
18+
import tools.jackson.databind.json.JsonMapper;
1819

1920
public class MscCodeUtils {
2021
private static final Logger LOGGER = LoggerFactory.getLogger(MscCodeUtils.class);
@@ -29,10 +30,10 @@ public class MscCodeUtils {
2930
@NonNull
3031
public static Optional<HashBiMap<String, String>> loadMscCodesFromJson(URL resourceUrl) throws MscCodeLoadingException {
3132

32-
ObjectMapper mapper = new ObjectMapper();
33+
ObjectMapper mapper = new JsonMapper();
3334
try {
3435
Map<String, String> mapping =
35-
mapper.readValue(resourceUrl, new TypeReference<>() {
36+
mapper.readValue(resourceUrl.openStream(), new TypeReference<>() {
3637
});
3738
HashBiMap<String, String> result = HashBiMap.create(mapping);
3839

@@ -41,7 +42,7 @@ public static Optional<HashBiMap<String, String>> loadMscCodesFromJson(URL resou
4142
}
4243

4344
return Optional.of(result);
44-
} catch (JsonParseException | JsonMappingException e) {
45+
} catch (StreamReadException | DatabindException e) {
4546
LOGGER.error("Error parsing MSC codes from JSON", e);
4647
throw new MscCodeLoadingException("Failed to parse MSC codes from JSON", e);
4748
} catch (IOException e) {

0 commit comments

Comments
 (0)