Skip to content

Commit

Permalink
Exception handling in JSONHelper & Version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamgahlout committed Feb 29, 2024
1 parent e103a18 commit 2209012
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.phsyberdome</groupId>
<artifactId>phsyberdome-sca-cli</artifactId>
<version>1.0.2-beta</version>
<version>1.0.3-beta</version>
<packaging>jar</packaging>
<build>
<plugins>
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/com/phsyberdome/drona/Utils/JSONHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.phsyberdome.drona.CLIHelper;
import com.phsyberdome.drona.Models.Pair;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.fusesource.jansi.Ansi;

/**
*
Expand All @@ -27,7 +26,7 @@ public static String convertToJson(Object object) {
try {
json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
}catch(JsonProcessingException e) {
Logger.getLogger(JSONHelper.class.getCanonicalName()).log(Level.WARNING, e.getLocalizedMessage());
CLIHelper.updateCurrentLine("Failed to convert to json!", Ansi.Color.RED);
return null;
}
return json;
Expand All @@ -38,7 +37,7 @@ public static <T> T convertToObj(Class<T> c,String json) {
ObjectMapper objectMapper = new ObjectMapper();
return (T) objectMapper.readValue(json, c);
}catch(Exception e) {
Logger.getLogger(JSONHelper.class.getCanonicalName()).log(Level.WARNING, e.getLocalizedMessage());
CLIHelper.updateCurrentLine("Failed to parse json!", Ansi.Color.RED);
}
return null;
}
Expand All @@ -49,8 +48,8 @@ public static String getValue(String keyPath,String json){
try {
root = objectMapper.readTree(json);
return root.at(keyPath).asText();
} catch (JsonProcessingException ex) {
Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception e){
CLIHelper.updateCurrentLine("Failed to parse json!", Ansi.Color.RED);
}
return null;
}
Expand All @@ -68,8 +67,8 @@ public static List<String> getValues(String keyPath,String json){
res.add(field.getKey());
}
return res;
} catch (JsonProcessingException ex) {
Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
CLIHelper.updateCurrentLine("Failed to parse json!", Ansi.Color.RED);
}
return null;
}
Expand Down

0 comments on commit 2209012

Please sign in to comment.