// Invocation Sending a json String and removal of key elements from the json String
String logString = json;
logString = maskedLog(logString);
logger.info("Response Data : "+logString);
public static String maskedLog(String logString){
for (String s : sensitiveKeys){
try {
logString= removeField(s, logString);
} catch (IOException e) {
logger.severe("Exception in Util maskedLog ");
}
}
return logString;
}
public static String removeField(String key, String jsonString) throws NullPointerException, IOException {
JSONArtifact artifact = (JSONArtifact) JSON.parse(jsonString);
removeField(key, artifact);
return artifact.toString();
}
private static void removeField(String key, Object json) {
if (json instanceof JSONObject) {
JSONObject o = (JSONObject) json;
o.remove(key);
Collection values = o.values();
traverseCollection(key, values);
} else if (json instanceof JSONArray) {
JSONArray array = (JSONArray) json;
traverseCollection(key, array);
}
}
private static void traverseCollection(String key, Collection collection) {
for (Object o : collection) {
removeField(key, o);
}
}
Throughout my professional and personal journey in software development, I've come across various technical challenges to tackle. These instances serve as valuable examples that I wish to retain. My hope is that they prove beneficial to fellow developers facing similar hurdles.
Tuesday, 18 July 2017
Brute Force Removal of Json Attribute from Json String : IBM JSON JAVA LIB
Subscribe to:
Posts (Atom)
AWS Certificate Manager - Import Certificate
How to import a certificate. Use Key Store Explorer to open the cert and export keypair in PEM format This will save a file cert.pem. Make ...

-
Code to validate a model POJO using jackson using annotations import java.io.IOException; import java.util.ArrayList; import java.util.Lis...
-
This is possible issue when the multiple jars of bouncy castle are loaded within the server. Steps to follow. 1) Make sure right correc...
-
Below code was used to consume a rest service Used this implementation to inject a factory bean with a trustFactory into my JaxWS spring b...