removed GSON

This commit is contained in:
Radek Davidek 2025-10-16 13:49:44 +02:00
parent 8063ebb638
commit 10ec54b5cf
4 changed files with 78 additions and 63 deletions

View File

@ -28,11 +28,6 @@
<artifactId>log4j-core</artifactId>
<version>2.24.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>

View File

@ -18,10 +18,9 @@ import javax.net.ssl.HttpsURLConnection;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import cz.trask.migration.config.ConfigManager;
import cz.trask.migration.model.APIList;
@ -36,8 +35,6 @@ public abstract class AbstractProcess {
protected static final String PARAM_SOURCE_APIM = "source_apim";
protected static final String VERSION_32 = "v32";
protected Gson gson;
protected ObjectMapper mapper;
protected ObjectMapper mapperYaml;
@ -45,11 +42,10 @@ public abstract class AbstractProcess {
protected ConfigManager config = ConfigManager.getInstance();
protected AbstractProcess() {
gson = new GsonBuilder().create();
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapperYaml = new ObjectMapper(new YAMLFactory());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
setTrustStoreCredentials();
@ -108,7 +104,7 @@ public abstract class AbstractProcess {
log.debug("Token response: HTTP Code " + response.getResponseCode() + " Json: " + response.getResponse());
TokenResponse resp = gson.fromJson(response.getResponse(), TokenResponse.class);
TokenResponse resp = mapper.readValue(response.getResponse(), TokenResponse.class);
return resp;
}
@ -138,7 +134,7 @@ public abstract class AbstractProcess {
log.debug(
"Register API response: HTTP Code " + response.getResponseCode() + " Json: " + response.getResponse());
RegisterResponse resp = gson.fromJson(response.getResponse(), RegisterResponse.class);
RegisterResponse resp = mapper.readValue(response.getResponse(), RegisterResponse.class);
return resp;
}
@ -307,7 +303,7 @@ public abstract class AbstractProcess {
log.debug("Listing APIs: HTTP Code " + response.getResponseCode() + " Data: " + response.getResponse());
listOfApis = gson.fromJson(response.getResponse(), APIList.class);
listOfApis = mapper.readValue(response.getResponse(), APIList.class);
if (response.getResponseCode() != 200)
log.error("Cannot list API. Something bad happened.");

View File

@ -15,9 +15,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import cz.trask.migration.AbstractProcess;
import cz.trask.migration.model.APIInfo;
@ -147,10 +146,8 @@ public class ImportToApicurio extends AbstractProcess {
}
// 3) Deserialize JSON responses
TypeToken<Map<String, Object>> mapType = new TypeToken<>() {
};
Map<String, Object> apiMap = gson.fromJson(apiInfoResp.getResponse(), mapType.getType());
Map<String, Object> subsMap = gson.fromJson(subsResp.getResponse(), mapType.getType());
Map<String, Object> apiMap = mapper.readValue(apiInfoResp.getResponse(), Map.class);
Map<String, Object> subsMap = mapper.readValue(subsResp.getResponse(), Map.class);
@SuppressWarnings("unchecked")
List<String> tagsList = (List<String>) apiMap.get("tags");
@ -174,7 +171,7 @@ public class ImportToApicurio extends AbstractProcess {
// 6) Update the swagger with the description and servers
Map<String, Object> swaggerMap = mapperYaml.readValue(swagger, Map.class);
JsonObject swaggerObj = gson.toJsonTree(swaggerMap).getAsJsonObject();
ObjectNode swaggerObj = mapperYaml.valueToTree(swaggerMap);
updateSwagger(swaggerObj, apiMap, fullDesc);
// 7) Prepare artifact creation/update
@ -242,41 +239,38 @@ public class ImportToApicurio extends AbstractProcess {
/* Helper methods */
/* --------------------------------------------------------------------- */
private void updateSwagger(JsonObject swagger, Map<String, Object> apiMap, String description) {
JsonObject info = swagger.getAsJsonObject("info");
if (info != null) {
info.addProperty("description", description);
}
private void updateSwagger(ObjectNode swagger, Map<String, Object> apiMap, String description) {
// Update "info.description"
ObjectNode info = (ObjectNode) swagger.get("info");
if (info != null) {
info.put("description", description);
}
// Build servers array
JsonArray servers = new JsonArray();
@SuppressWarnings("unchecked")
List<Map<String, Object>> endpoints = (List<Map<String, Object>>) apiMap.get("endpointURLs");
if (endpoints != null) {
for (Map<String, Object> env : endpoints) {
@SuppressWarnings("unchecked")
Map<String, String> urls = (Map<String, String>) env.get("URLs");
if (urls == null || urls.isEmpty())
continue;
// Build "servers" array
ArrayNode servers = mapper.createArrayNode();
JsonObject server = new JsonObject();
urls.forEach((k, v) -> {
if (v != null && !v.isBlank()) {
if (k.equals("https")) {
server.addProperty("url", v);
} else if (k.equals("wss")) {
server.addProperty("url", v);
}
}
});
server.addProperty("description", "Gateway: " + env.getOrDefault("environmentName", ""));
servers.add(server);
}
}
List<Map<String, Object>> endpoints = (List<Map<String, Object>>) apiMap.get("endpointURLs");
if (endpoints != null) {
for (Map<String, Object> env : endpoints) {
Map<String, String> urls = (Map<String, String>) env.get("URLs");
if (urls == null || urls.isEmpty()) continue;
swagger.remove("servers");
swagger.add("servers", servers);
}
ObjectNode server = mapper.createObjectNode();
urls.forEach((k, v) -> {
if (v != null && !v.isBlank()) {
if (k.equals("https") || k.equals("wss")) {
server.put("url", v);
}
}
});
server.put("description", "Gateway: " + env.getOrDefault("environmentName", ""));
servers.add(server);
}
}
// Replace "servers" node
swagger.set("servers", servers);
}
private void addSubscriptionsToProps(Map<String, String> props, Map<String, Object> subsMap) {
if (subsMap == null || !subsMap.containsKey("list"))

View File

@ -1,17 +1,23 @@
package cz.trask.migration.model;
public class RegisterResponse {
import com.fasterxml.jackson.annotation.JsonProperty;
// {"clientId":"QRGgaoQpiRfd6K8KZfU2hZsXoqAa","clientName":"admin_rest_api_publisher","callBackURL":"www.google.lk","clientSecret":"5o_ncm_br0wr8yOXc_ouXOWfOWsa","isSaasApplication":true,"appOwner":"admin","jsonString":"{\"grant_types\":\"password
// refresh_token\",\"redirect_uris\":\"www.google.lk\",\"client_name\":\"admin_rest_api_publisher\"}","jsonAppAttribute":"{}","tokenType":null}
public class RegisterResponse {
private String clientId;
private String clientName;
private String callBackURL;
private String clientSecret;
private boolean isSaasApplication;
private String appOwner;
@JsonProperty("isSaasApplication")
private boolean saasApplication;
private String appOwner;
private String jsonString;
private String jsonAppAttribute;
private String tokenType;
// getters a setters
public String getClientId() {
return clientId;
}
@ -45,11 +51,11 @@ public class RegisterResponse {
}
public boolean isSaasApplication() {
return isSaasApplication;
return saasApplication;
}
public void setSaasApplication(boolean isSaasApplication) {
this.isSaasApplication = isSaasApplication;
public void setSaasApplication(boolean saasApplication) {
this.saasApplication = saasApplication;
}
public String getAppOwner() {
@ -59,4 +65,28 @@ public class RegisterResponse {
public void setAppOwner(String appOwner) {
this.appOwner = appOwner;
}
public String getJsonString() {
return jsonString;
}
public void setJsonString(String jsonString) {
this.jsonString = jsonString;
}
public String getJsonAppAttribute() {
return jsonAppAttribute;
}
public void setJsonAppAttribute(String jsonAppAttribute) {
this.jsonAppAttribute = jsonAppAttribute;
}
public String getTokenType() {
return tokenType;
}
public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}
}