Browse Source

changes in tovalid json

master
yoganandhan 1 year ago
parent
commit
e6afcc82e4
  1. 48
      src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java

48
src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java

@ -116,20 +116,47 @@ public class BirthAndDeathDetailsService {
return mapper.readValue(cleanJson, new TypeReference<Map<String, Object>>() {}); return mapper.readValue(cleanJson, new TypeReference<Map<String, Object>>() {});
} }
private String clean(String input) {
if (input == null) return "";
return input.replace("\"", "").trim(); // remove unescaped quotes
}
// private String sanitizeJsonResponse(String rawJson) {
// if (rawJson == null) return "";
//
// // Remove illegal control characters (but keep line breaks if needed)
// return rawJson
// .replace("\\", "\\\\") // Escape backslashes
// .replaceAll("[\\p{Cntrl}&&[^\r\n\t]]", "") // Remove non-printable control characters (except tabs/newlines)
// .replaceAll("\t", "") // Remove tab characters explicitly (common cause of error)
// .replaceAll("\\s*:\\s*\n\\s*\"", ":\"") // Fix broken key-value splits
// .replaceAll("\r", "") // Remove carriage return if any
// .replaceAll("\n", "") // Optionally remove newlines if JSON is malformed across lines
// .replaceAll(",\\s*\\[", "[") // Remove comma before array start
// .replaceAll("\\[\\s*,", "[") // Remove comma after array start
// .replaceAll(",\\s*\\]", "]"); // Remove trailing comma in array
// }
private String sanitizeJsonResponse(String rawJson) { private String sanitizeJsonResponse(String rawJson) {
if (rawJson == null) return ""; if (rawJson == null) return "";
// Remove illegal control characters (but keep line breaks if needed)
return rawJson return rawJson
.replace("\\", "\\\\") // Escape backslashes
.replaceAll("[\\p{Cntrl}&&[^\r\n\t]]", "") // Remove non-printable control characters (except tabs/newlines)
.replaceAll("\t", "") // Remove tab characters explicitly (common cause of error)
.replaceAll("\\s*:\\s*\n\\s*\"", ":\"") // Fix broken key-value splits
.replaceAll("\r", "") // Remove carriage return if any
.replaceAll("\n", "") // Optionally remove newlines if JSON is malformed across lines
.replaceAll(",\\s*\\[", "[") // Remove comma before array start
.replaceAll("\\[\\s*,", "[") // Remove comma after array start
.replaceAll(",\\s*\\]", "]"); // Remove trailing comma in array
.replace("\\", "\\\\") // Escape backslashes
.replaceAll("[\\p{Cntrl}&&[^\r\n\t]]", "") // Remove non-printable control characters
.replaceAll("\t", "") // Remove tab characters
.replaceAll("\\s*:\\s*\n\\s*\"", ":\"") // Fix broken key-value splits
.replaceAll("\r", "") // Remove carriage return
.replaceAll("\n", "") // Remove newlines
.replaceAll(",\\s*\\[", "[") // Remove comma before array start
.replaceAll("\\[\\s*,", "[") // Remove comma after array start
.replaceAll(",\\s*\\]", "]") // Remove trailing comma in array
.replaceAll("\"\"\"", "\"\"") // ← fix triple quotes
.replaceAll("\"{3,}", "\"") // ← fallback: collapse 3+ quotes to 1
.replaceAll(":(\\s*)\"{2,}\"", ":\"\""); // ← handle `:"""` to `:""`
} }
@ -137,6 +164,7 @@ public class BirthAndDeathDetailsService {
@Transactional @Transactional
public ResponseEntity<?> saveNewUser(String user_name, String user_address, String user_mobile) { public ResponseEntity<?> saveNewUser(String user_name, String user_address, String user_mobile) {
Map<String, Object> result = new HashMap(); Map<String, Object> result = new HashMap();

Loading…
Cancel
Save