Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.gradle.api.tasks.Copy;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

import org.springframework.boot.build.antora.AntoraAsciidocAttributes;
import org.springframework.boot.build.antora.GenerateAntoraPlaybook;
Expand Down Expand Up @@ -197,8 +197,8 @@ private void logWarningIfNodeModulesInUserHome(Project project) {

private String getUiBundleUrl(Project project) {
File packageJson = project.getRootProject().file("antora/package.json");
ObjectMapper objectMapper = new ObjectMapper();
Map<?, ?> json = objectMapper.readerFor(Map.class).readValue(packageJson);
JsonMapper jsonMapper = new JsonMapper();
Map<?, ?> json = jsonMapper.readerFor(Map.class).readValue(packageJson);
Map<?, ?> config = (json != null) ? (Map<?, ?>) json.get("config") : null;
String url = (config != null) ? (String) config.get("ui-bundle-url") : null;
Assert.state(StringUtils.hasText(url.toString()), "package.json has not ui-bundle-url config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

/**
Expand All @@ -37,25 +36,25 @@
*/
public record ResolvedBom(Id id, List<ResolvedLibrary> libraries) {

private static final ObjectMapper objectMapper;
private static final JsonMapper jsonMapper;

static {
objectMapper = JsonMapper.builder()
jsonMapper = JsonMapper.builder()
.changeDefaultPropertyInclusion((value) -> value.withContentInclusion(Include.NON_EMPTY))
.build();
}

public static ResolvedBom readFrom(File file) {
try (FileReader reader = new FileReader(file)) {
return objectMapper.readValue(reader, ResolvedBom.class);
return jsonMapper.readValue(reader, ResolvedBom.class);
}
catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}

public void writeTo(Writer writer) {
objectMapper.writeValue(writer, this);
jsonMapper.writeValue(writer, this);
}

public record ResolvedLibrary(String name, String version, String versionProperty, List<Id> managedDependencies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.gradle.api.tasks.SourceTask;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.VerificationException;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

/**
* {@link SourceTask} that checks additional Spring configuration metadata files.
Expand Down Expand Up @@ -75,11 +75,11 @@ void check() throws IOException {

@SuppressWarnings("unchecked")
private Report createReport() {
ObjectMapper objectMapper = new ObjectMapper();
JsonMapper jsonMapper = new JsonMapper();
Report report = new Report();
for (File file : getSource().getFiles()) {
Analysis analysis = report.analysis(this.projectDir.toPath().relativize(file.toPath()));
Map<String, Object> json = objectMapper.readValue(file, Map.class);
Map<String, Object> json = jsonMapper.readValue(file, Map.class);
check("groups", json, analysis);
check("properties", json, analysis);
check("hints", json, analysis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.gradle.api.tasks.SourceTask;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.VerificationException;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

/**
* {@link SourceTask} that checks {@code spring-configuration-metadata.json} files.
Expand Down Expand Up @@ -75,10 +75,10 @@ void check() throws IOException {

@SuppressWarnings("unchecked")
private Report createReport() {
ObjectMapper objectMapper = new ObjectMapper();
JsonMapper jsonMapper = new JsonMapper();
File file = getMetadataLocation().get().getAsFile();
Report report = new Report(this.projectRoot.relativize(file.toPath()));
Map<String, Object> json = objectMapper.readValue(file, Map.class);
Map<String, Object> json = jsonMapper.readValue(file, Map.class);
List<Map<String, Object>> properties = (List<Map<String, Object>>) json.get("properties");
for (Map<String, Object> property : properties) {
String name = (String) property.get("name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Map;
import java.util.stream.Stream;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

/**
* Configuration properties read from one or more
Expand Down Expand Up @@ -55,10 +55,10 @@ Stream<ConfigurationProperty> stream() {

@SuppressWarnings("unchecked")
static ConfigurationProperties fromFiles(Iterable<File> files) {
ObjectMapper objectMapper = new ObjectMapper();
JsonMapper jsonMapper = new JsonMapper();
List<ConfigurationProperty> properties = new ArrayList<>();
for (File file : files) {
Map<String, Object> json = objectMapper.readValue(file, Map.class);
Map<String, Object> json = jsonMapper.readValue(file, Map.class);
for (Map<String, Object> property : (List<Map<String, Object>>) json.get("properties")) {
properties.add(ConfigurationProperty.fromJsonProperties(property));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import org.jspecify.annotations.Nullable;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
import tools.jackson.databind.node.ArrayNode;
import tools.jackson.databind.node.ObjectNode;

Expand Down Expand Up @@ -67,7 +67,7 @@ public class ImageArchive implements TarArchive {
private static final IOConsumer<Update> NO_UPDATES = (update) -> {
};

private final ObjectMapper objectMapper;
private final JsonMapper jsonMapper;

private final ImageConfig imageConfig;

Expand All @@ -85,10 +85,10 @@ public class ImageArchive implements TarArchive {

private final List<Layer> newLayers;

ImageArchive(ObjectMapper objectMapper, ImageConfig imageConfig, Instant createDate, @Nullable ImageReference tag,
ImageArchive(JsonMapper jsonMapper, ImageConfig imageConfig, Instant createDate, @Nullable ImageReference tag,
String os, @Nullable String architecture, @Nullable String variant, List<LayerId> existingLayers,
List<Layer> newLayers) {
this.objectMapper = objectMapper;
this.jsonMapper = jsonMapper;
this.imageConfig = imageConfig;
this.createDate = createDate;
this.tag = tag;
Expand Down Expand Up @@ -158,7 +158,7 @@ private LayerId writeLayer(Layout writer, Layer layer) throws IOException {
private String writeConfig(Layout writer, List<LayerId> writtenLayers) throws IOException {
try {
ObjectNode config = createConfig(writtenLayers);
String json = this.objectMapper.writeValueAsString(config).replace("\r\n", "\n");
String json = this.jsonMapper.writeValueAsString(config).replace("\r\n", "\n");
MessageDigest digest = MessageDigest.getInstance("SHA-256");
InspectedContent content = InspectedContent.of(Content.of(json), digest::update);
String name = LayerId.ofSha256Digest(digest.digest()).getHash() + ".json";
Expand All @@ -171,7 +171,7 @@ private String writeConfig(Layout writer, List<LayerId> writtenLayers) throws IO
}

private ObjectNode createConfig(List<LayerId> writtenLayers) {
ObjectNode config = this.objectMapper.createObjectNode();
ObjectNode config = this.jsonMapper.createObjectNode();
config.set("Config", this.imageConfig.getNodeCopy());
config.set("Created", config.stringNode(getCreatedDate()));
config.set("History", createHistory(writtenLayers));
Expand All @@ -187,7 +187,7 @@ private String getCreatedDate() {
}

private JsonNode createHistory(List<LayerId> writtenLayers) {
ArrayNode history = this.objectMapper.createArrayNode();
ArrayNode history = this.jsonMapper.createArrayNode();
int size = this.existingLayers.size() + writtenLayers.size();
for (int i = 0; i < size; i++) {
history.addObject();
Expand All @@ -196,7 +196,7 @@ private JsonNode createHistory(List<LayerId> writtenLayers) {
}

private JsonNode createRootFs(List<LayerId> writtenLayers) {
ObjectNode rootFs = this.objectMapper.createObjectNode();
ObjectNode rootFs = this.jsonMapper.createObjectNode();
ArrayNode diffIds = rootFs.putArray("diff_ids");
this.existingLayers.stream().map(Object::toString).forEach(diffIds::add);
writtenLayers.stream().map(Object::toString).forEach(diffIds::add);
Expand All @@ -205,12 +205,12 @@ private JsonNode createRootFs(List<LayerId> writtenLayers) {

private void writeManifest(Layout writer, String config, List<LayerId> writtenLayers) throws IOException {
ArrayNode manifest = createManifest(config, writtenLayers);
String manifestJson = this.objectMapper.writeValueAsString(manifest);
String manifestJson = this.jsonMapper.writeValueAsString(manifest);
writer.file("manifest.json", Owner.ROOT, Content.of(manifestJson));
}

private ArrayNode createManifest(String config, List<LayerId> writtenLayers) {
ArrayNode manifest = this.objectMapper.createArrayNode();
ArrayNode manifest = this.jsonMapper.createArrayNode();
ObjectNode entry = manifest.addObject();
entry.set("Config", entry.stringNode(config));
entry.set("Layers", getManifestLayers(writtenLayers));
Expand All @@ -221,7 +221,7 @@ private ArrayNode createManifest(String config, List<LayerId> writtenLayers) {
}

private ArrayNode getManifestLayers(List<LayerId> writtenLayers) {
ArrayNode layers = this.objectMapper.createArrayNode();
ArrayNode layers = this.jsonMapper.createArrayNode();
for (int i = 0; i < this.existingLayers.size(); i++) {
layers.add(EMPTY_LAYER_NAME_PREFIX + i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.jspecify.annotations.Nullable;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

import org.springframework.util.Assert;
Expand Down Expand Up @@ -162,7 +161,7 @@ protected static <T extends MappedObject> T getRoot(Object proxy) {
* @throws IOException on IO error
*/
protected static <T extends MappedObject> T of(String content, Function<JsonNode, T> factory) throws IOException {
return of(content, ObjectMapper::readTree, factory);
return of(content, JsonMapper::readTree, factory);
}

/**
Expand All @@ -175,7 +174,7 @@ protected static <T extends MappedObject> T of(String content, Function<JsonNode
*/
protected static <T extends MappedObject> T of(InputStream content, Function<JsonNode, T> factory)
throws IOException {
return of(StreamUtils.nonClosing(content), ObjectMapper::readTree, factory);
return of(StreamUtils.nonClosing(content), JsonMapper::readTree, factory);
}

/**
Expand Down Expand Up @@ -205,12 +204,12 @@ protected interface ContentReader<C> {

/**
* Read JSON content as a {@link JsonNode}.
* @param objectMapper the source object mapper
* @param jsonMapper the source json mapper
* @param content the content to read
* @return a {@link JsonNode}
* @throws IOException on IO error
*/
JsonNode read(ObjectMapper objectMapper, C content) throws IOException;
JsonNode read(JsonMapper jsonMapper, C content) throws IOException;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import tools.jackson.databind.DeserializationFeature;
import tools.jackson.databind.JavaType;
import tools.jackson.databind.MapperFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

/**
Expand All @@ -34,7 +33,7 @@
*/
final class DockerJson {

private static final ObjectMapper objectMapper = JsonMapper.builder()
private static final JsonMapper jsonMapper = JsonMapper.builder()
.defaultLocale(Locale.ENGLISH)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
Expand All @@ -53,7 +52,7 @@ private DockerJson() {
*/
static <T> List<T> deserializeToList(String json, Class<T> itemType) {
if (json.startsWith("[")) {
JavaType javaType = objectMapper.getTypeFactory().constructCollectionType(List.class, itemType);
JavaType javaType = jsonMapper.getTypeFactory().constructCollectionType(List.class, itemType);
return deserialize(json, javaType);
}
return json.trim().lines().map((line) -> deserialize(line, itemType)).toList();
Expand All @@ -67,11 +66,11 @@ static <T> List<T> deserializeToList(String json, Class<T> itemType) {
* @return the deserialized result
*/
static <T> T deserialize(String json, Class<T> type) {
return deserialize(json, objectMapper.getTypeFactory().constructType(type));
return deserialize(json, jsonMapper.getTypeFactory().constructType(type));
}

private static <T> T deserialize(String json, JavaType type) {
return objectMapper.readValue(json.trim(), type);
return jsonMapper.readValue(json.trim(), type);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonGenerator;
import tools.jackson.databind.JavaType;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectReader;
import tools.jackson.databind.ObjectWriter;
import tools.jackson.databind.json.JsonMapper;
Expand Down Expand Up @@ -214,13 +213,13 @@ protected AbstractJsonMarshalTester<Object> createTester(Class<?> resourceLoadCl

private static final class JacksonJsonProvider extends AbstractJsonProvider {

private final ObjectMapper objectMapper;
private final JsonMapper jsonMapper;

private final ObjectReader objectReader;

private JacksonJsonProvider(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
this.objectReader = objectMapper.reader().forType(Object.class);
private JacksonJsonProvider(JsonMapper jsonMapper) {
this.jsonMapper = jsonMapper;
this.objectReader = jsonMapper.reader().forType(Object.class);
}

@Override
Expand Down Expand Up @@ -256,8 +255,8 @@ public Object parse(InputStream jsonStream, String charset) throws InvalidJsonEx
@Override
public String toJson(Object obj) {
StringWriter writer = new StringWriter();
try (JsonGenerator generator = this.objectMapper.createGenerator(writer)) {
this.objectMapper.writeValue(generator, obj);
try (JsonGenerator generator = this.jsonMapper.createGenerator(writer)) {
this.jsonMapper.writeValue(generator, obj);
}
catch (JacksonException ex) {
throw new InvalidJsonException(ex);
Expand All @@ -279,10 +278,10 @@ public Object createMap() {

private static final class JacksonMappingProvider implements MappingProvider {

private final ObjectMapper objectMapper;
private final JsonMapper jsonMapper;

private JacksonMappingProvider(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
private JacksonMappingProvider(JsonMapper jsonMapper) {
this.jsonMapper = jsonMapper;
}

@Override
Expand All @@ -291,7 +290,7 @@ private JacksonMappingProvider(ObjectMapper objectMapper) {
return null;
}
try {
return this.objectMapper.convertValue(source, targetType);
return this.jsonMapper.convertValue(source, targetType);
}
catch (Exception ex) {
throw new MappingException(ex);
Expand All @@ -305,9 +304,9 @@ private JacksonMappingProvider(ObjectMapper objectMapper) {
if (source == null) {
return null;
}
JavaType type = this.objectMapper.getTypeFactory().constructType(targetType.getType());
JavaType type = this.jsonMapper.getTypeFactory().constructType(targetType.getType());
try {
return (T) this.objectMapper.convertValue(source, type);
return (T) this.jsonMapper.convertValue(source, type);
}
catch (Exception ex) {
throw new MappingException(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import tools.jackson.databind.ObjectMapper;

/**
* Thin wrapper to adapt Jackson 2 {@link ObjectMapper} to {@link JsonParser}.
* Thin wrapper to adapt Jackson 3 {@link ObjectMapper} to {@link JsonParser}.
*
* @author Dave Syer
* @since 1.0.0
Expand Down
Loading