Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#557: fix json mapping #617

Merged
merged 7 commits into from
Sep 17, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE
Release with new features and bugfixes:

* https://github.com/devonfw/IDEasy/issues/553[#554]: Missmatch of IDE_ROOT
* https://github.com/devonfw/IDEasy/issues/557[#557]: Failed to update tomcat: Cannot find a (Map) Key deserializer for type VersionRange

The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/13?closed=1[milestone 2024.09.002].

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.devonfw.tools.ide.github;

import com.devonfw.tools.ide.common.JsonVersionItem;
import com.devonfw.tools.ide.json.JsonVersionItem;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.ArrayList;

import com.devonfw.tools.ide.common.JsonObject;
import com.devonfw.tools.ide.json.JsonObject;

/**
* {@link JsonObject} for {@link GithubTag}s (refs).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.devonfw.tools.ide.json.mapping;
package com.devonfw.tools.ide.json;

import com.devonfw.tools.ide.version.VersionIdentifier;
import com.devonfw.tools.ide.version.VersionRange;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

/**
Expand All @@ -22,6 +25,11 @@ public static ObjectMapper create() {
mapper = mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper = mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper = mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
SimpleModule customModule = new SimpleModule();
customModule.addDeserializer(VersionIdentifier.class, new VersionIdentifierDeserializer());
customModule.addDeserializer(VersionRange.class, new VersionRangeDeserializer());
customModule.addKeyDeserializer(VersionRange.class, new VersionRangeKeyDeserializer());
mapper = mapper.registerModule(customModule);
return mapper;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devonfw.tools.ide.common;
package com.devonfw.tools.ide.json;

/**
* Interface for a data object that can be read from and written to JSON.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devonfw.tools.ide.common;
package com.devonfw.tools.ide.json;

/**
* Interface for a data object that can be read from and written to JSON.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.devonfw.tools.ide.json;

import java.io.IOException;

import com.devonfw.tools.ide.version.VersionIdentifier;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

/**
* {@link JsonDeserializer} for {@link VersionIdentifier}.
*/
public class VersionIdentifierDeserializer extends JsonDeserializer<VersionIdentifier> {

@Override
public VersionIdentifier deserialize(JsonParser p, DeserializationContext context) throws IOException, JacksonException {

JsonToken token = p.getCurrentToken();
if (token == JsonToken.VALUE_STRING) {
return VersionIdentifier.of(p.getValueAsString());
} else {
throw new IllegalArgumentException("Invalid JSON for VersionRange!");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.devonfw.tools.ide.json;

import java.io.IOException;

import com.devonfw.tools.ide.version.VersionRange;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

/**
* {@link JsonDeserializer} for {@link VersionRange}.
*/
public class VersionRangeDeserializer extends JsonDeserializer<VersionRange> {

@Override
public VersionRange deserialize(JsonParser p, DeserializationContext context) throws IOException, JacksonException {

JsonToken token = p.getCurrentToken();
if (token == JsonToken.VALUE_STRING) {
return VersionRange.of(p.getValueAsString());
} else {
throw new IllegalArgumentException("Invalid JSON for VersionRange!");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.devonfw.tools.ide.json;

import java.io.IOException;

import com.devonfw.tools.ide.version.VersionRange;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.KeyDeserializer;

/**
* {@link KeyDeserializer} for {@link VersionRange}.
*/
public class VersionRangeKeyDeserializer extends KeyDeserializer {

@Override
public Object deserializeKey(String key, DeserializationContext context) throws IOException {

return VersionRange.of(key);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.devonfw.tools.ide.npm;

import com.devonfw.tools.ide.common.JsonObject;
import com.devonfw.tools.ide.json.JsonObject;

/**
* {@link JsonObject} for Npm.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.devonfw.tools.ide.npm;

import com.devonfw.tools.ide.common.JsonVersionItem;
import com.devonfw.tools.ide.json.JsonVersionItem;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.HashMap;
import java.util.Map;

import com.devonfw.tools.ide.common.JsonObject;
import com.devonfw.tools.ide.json.JsonObject;
import com.fasterxml.jackson.annotation.JsonAnySetter;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.url.model.file.UrlDependencyFile;
import com.devonfw.tools.ide.url.model.file.dependencyJson.DependencyInfo;
import com.devonfw.tools.ide.url.model.file.json.DependencyInfo;
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
import com.devonfw.tools.ide.version.VersionIdentifier;
import com.devonfw.tools.ide.version.VersionRange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.devonfw.tools.ide.process.EnvironmentContext;
import com.devonfw.tools.ide.repo.ToolRepository;
import com.devonfw.tools.ide.step.Step;
import com.devonfw.tools.ide.url.model.file.dependencyJson.DependencyInfo;
import com.devonfw.tools.ide.url.model.file.json.DependencyInfo;
import com.devonfw.tools.ide.version.VersionIdentifier;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.devonfw.tools.ide.tool.androidstudio;

import com.devonfw.tools.ide.common.JsonObject;
import com.devonfw.tools.ide.json.JsonObject;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import com.devonfw.tools.ide.common.JsonVersionItem;
import com.devonfw.tools.ide.json.JsonVersionItem;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.devonfw.tools.ide.tool.androidstudio;

import com.devonfw.tools.ide.common.JsonObject;
import com.devonfw.tools.ide.json.JsonObject;

/**
* {@link JsonObject} for Android Studio content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import com.devonfw.tools.ide.common.JsonObject;
import com.devonfw.tools.ide.json.JsonObject;

/**
* {@link JsonObject} for Intellij content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Map;

import com.devonfw.tools.ide.common.JsonVersionItem;
import com.devonfw.tools.ide.json.JsonVersionItem;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.Collection;
import java.util.List;

import com.devonfw.tools.ide.common.JsonVersionItem;
import com.devonfw.tools.ide.json.mapping.JsonMapping;
import com.devonfw.tools.ide.json.JsonMapping;
import com.devonfw.tools.ide.json.JsonVersionItem;
import com.devonfw.tools.ide.os.OperatingSystem;
import com.devonfw.tools.ide.os.SystemArchitecture;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import com.devonfw.tools.ide.common.JsonObject;
import com.devonfw.tools.ide.json.JsonObject;

/**
* {@link JsonObject} for Java versions from adoptium REST API.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.devonfw.tools.ide.tool.java;

import com.devonfw.tools.ide.common.JsonVersionItem;
import com.devonfw.tools.ide.json.JsonVersionItem;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import com.devonfw.tools.ide.common.JsonObject;
import com.devonfw.tools.ide.json.JsonObject;

/**
* Java object to represent the JSON of Python release information. This is the root {@link JsonObject}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import com.devonfw.tools.ide.common.JsonVersionItem;
import com.devonfw.tools.ide.json.JsonVersionItem;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.tools.ide.json.mapping.JsonMapping;
import com.devonfw.tools.ide.json.JsonMapping;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
import com.devonfw.tools.ide.url.updater.JsonUrlUpdater;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import java.util.List;
import java.util.Map;

import com.devonfw.tools.ide.json.mapping.JsonMapping;
import com.devonfw.tools.ide.url.model.file.dependencyJson.DependencyInfo;
import com.devonfw.tools.ide.json.JsonMapping;
import com.devonfw.tools.ide.url.model.file.json.DependencyInfo;
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
import com.devonfw.tools.ide.version.VersionIdentifier;
import com.devonfw.tools.ide.version.VersionRange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

import com.devonfw.tools.ide.json.mapping.JsonMapping;
import com.devonfw.tools.ide.json.JsonMapping;
import com.devonfw.tools.ide.url.model.file.json.StatusJson;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devonfw.tools.ide.url.model.file.dependencyJson;
package com.devonfw.tools.ide.url.model.file.json;

import com.devonfw.tools.ide.version.VersionRange;

Expand All @@ -9,7 +9,7 @@ public final class DependencyInfo {

private String tool;

private String versionRange;
private VersionRange versionRange;

/**
* @return the dependency name
Expand All @@ -19,12 +19,21 @@ public String getTool() {
return this.tool;
}

void setTool(String tool) {

this.tool = tool;
}

/**
* @return the VersionRange of the dependency
*/
public VersionRange getVersionRange() {

return VersionRange.of(this.versionRange);
return this.versionRange;
}

void setVersionRange(VersionRange versionRange) {

this.versionRange = versionRange;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.tools.ide.common.JsonObject;
import com.devonfw.tools.ide.common.JsonVersionItem;
import com.devonfw.tools.ide.json.mapping.JsonMapping;
import com.devonfw.tools.ide.json.JsonMapping;
import com.devonfw.tools.ide.json.JsonObject;
import com.devonfw.tools.ide.json.JsonVersionItem;
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
import com.devonfw.tools.ide.url.model.folder.UrlRepository;
import com.devonfw.tools.ide.url.model.folder.UrlTool;
Expand Down
Loading
Loading