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> <artifactId>log4j-core</artifactId>
<version>2.24.2</version> <version>2.24.2</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.13.1</version>
</dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <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.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; 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.config.ConfigManager;
import cz.trask.migration.model.APIList; 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 PARAM_SOURCE_APIM = "source_apim";
protected static final String VERSION_32 = "v32"; protected static final String VERSION_32 = "v32";
protected Gson gson;
protected ObjectMapper mapper; protected ObjectMapper mapper;
protected ObjectMapper mapperYaml; protected ObjectMapper mapperYaml;
@ -45,11 +42,10 @@ public abstract class AbstractProcess {
protected ConfigManager config = ConfigManager.getInstance(); protected ConfigManager config = ConfigManager.getInstance();
protected AbstractProcess() { protected AbstractProcess() {
gson = new GsonBuilder().create();
mapper = new ObjectMapper(); mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapperYaml = new ObjectMapper(new YAMLFactory()); mapperYaml = new ObjectMapper(new YAMLFactory());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
setTrustStoreCredentials(); setTrustStoreCredentials();
@ -108,7 +104,7 @@ public abstract class AbstractProcess {
log.debug("Token response: HTTP Code " + response.getResponseCode() + " Json: " + response.getResponse()); 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; return resp;
} }
@ -138,7 +134,7 @@ public abstract class AbstractProcess {
log.debug( log.debug(
"Register API response: HTTP Code " + response.getResponseCode() + " Json: " + response.getResponse()); "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; return resp;
} }
@ -307,7 +303,7 @@ public abstract class AbstractProcess {
log.debug("Listing APIs: HTTP Code " + response.getResponseCode() + " Data: " + response.getResponse()); 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) if (response.getResponseCode() != 200)
log.error("Cannot list API. Something bad happened."); 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.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.google.gson.JsonArray; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.gson.JsonObject; import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.reflect.TypeToken;
import cz.trask.migration.AbstractProcess; import cz.trask.migration.AbstractProcess;
import cz.trask.migration.model.APIInfo; import cz.trask.migration.model.APIInfo;
@ -147,10 +146,8 @@ public class ImportToApicurio extends AbstractProcess {
} }
// 3) Deserialize JSON responses // 3) Deserialize JSON responses
TypeToken<Map<String, Object>> mapType = new TypeToken<>() { Map<String, Object> apiMap = mapper.readValue(apiInfoResp.getResponse(), Map.class);
}; Map<String, Object> subsMap = mapper.readValue(subsResp.getResponse(), Map.class);
Map<String, Object> apiMap = gson.fromJson(apiInfoResp.getResponse(), mapType.getType());
Map<String, Object> subsMap = gson.fromJson(subsResp.getResponse(), mapType.getType());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<String> tagsList = (List<String>) apiMap.get("tags"); 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 // 6) Update the swagger with the description and servers
Map<String, Object> swaggerMap = mapperYaml.readValue(swagger, Map.class); Map<String, Object> swaggerMap = mapperYaml.readValue(swagger, Map.class);
JsonObject swaggerObj = gson.toJsonTree(swaggerMap).getAsJsonObject(); ObjectNode swaggerObj = mapperYaml.valueToTree(swaggerMap);
updateSwagger(swaggerObj, apiMap, fullDesc); updateSwagger(swaggerObj, apiMap, fullDesc);
// 7) Prepare artifact creation/update // 7) Prepare artifact creation/update
@ -242,40 +239,37 @@ public class ImportToApicurio extends AbstractProcess {
/* Helper methods */ /* Helper methods */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
private void updateSwagger(JsonObject swagger, Map<String, Object> apiMap, String description) { private void updateSwagger(ObjectNode swagger, Map<String, Object> apiMap, String description) {
JsonObject info = swagger.getAsJsonObject("info"); // Update "info.description"
ObjectNode info = (ObjectNode) swagger.get("info");
if (info != null) { if (info != null) {
info.addProperty("description", description); info.put("description", description);
} }
// Build servers array // Build "servers" array
JsonArray servers = new JsonArray(); ArrayNode servers = mapper.createArrayNode();
@SuppressWarnings("unchecked")
List<Map<String, Object>> endpoints = (List<Map<String, Object>>) apiMap.get("endpointURLs"); List<Map<String, Object>> endpoints = (List<Map<String, Object>>) apiMap.get("endpointURLs");
if (endpoints != null) { if (endpoints != null) {
for (Map<String, Object> env : endpoints) { for (Map<String, Object> env : endpoints) {
@SuppressWarnings("unchecked")
Map<String, String> urls = (Map<String, String>) env.get("URLs"); Map<String, String> urls = (Map<String, String>) env.get("URLs");
if (urls == null || urls.isEmpty()) if (urls == null || urls.isEmpty()) continue;
continue;
JsonObject server = new JsonObject(); ObjectNode server = mapper.createObjectNode();
urls.forEach((k, v) -> { urls.forEach((k, v) -> {
if (v != null && !v.isBlank()) { if (v != null && !v.isBlank()) {
if (k.equals("https")) { if (k.equals("https") || k.equals("wss")) {
server.addProperty("url", v); server.put("url", v);
} else if (k.equals("wss")) {
server.addProperty("url", v);
} }
} }
}); });
server.addProperty("description", "Gateway: " + env.getOrDefault("environmentName", "")); server.put("description", "Gateway: " + env.getOrDefault("environmentName", ""));
servers.add(server); servers.add(server);
} }
} }
swagger.remove("servers"); // Replace "servers" node
swagger.add("servers", servers); swagger.set("servers", servers);
} }
private void addSubscriptionsToProps(Map<String, String> props, Map<String, Object> subsMap) { private void addSubscriptionsToProps(Map<String, String> props, Map<String, Object> subsMap) {

View File

@ -1,17 +1,23 @@
package cz.trask.migration.model; 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 public class RegisterResponse {
// refresh_token\",\"redirect_uris\":\"www.google.lk\",\"client_name\":\"admin_rest_api_publisher\"}","jsonAppAttribute":"{}","tokenType":null}
private String clientId; private String clientId;
private String clientName; private String clientName;
private String callBackURL; private String callBackURL;
private String clientSecret; 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() { public String getClientId() {
return clientId; return clientId;
} }
@ -45,11 +51,11 @@ public class RegisterResponse {
} }
public boolean isSaasApplication() { public boolean isSaasApplication() {
return isSaasApplication; return saasApplication;
} }
public void setSaasApplication(boolean isSaasApplication) { public void setSaasApplication(boolean saasApplication) {
this.isSaasApplication = isSaasApplication; this.saasApplication = saasApplication;
} }
public String getAppOwner() { public String getAppOwner() {
@ -59,4 +65,28 @@ public class RegisterResponse {
public void setAppOwner(String appOwner) { public void setAppOwner(String appOwner) {
this.appOwner = 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;
}
} }