• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk-gen / #55

08 Apr 2025 10:56AM UTC coverage: 35.205% (+0.01%) from 35.192%
#55

Pull #267

github

web-flow
Merge 97cf143a4 into c93ae3b21
Pull Request #267: feat: Support sensitive data sanitization in errors (box/box-codegen#695)

40 of 80 new or added lines in 8 files covered. (50.0%)

7 existing lines in 6 files now uncovered.

15268 of 43369 relevant lines covered (35.2%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.14
/src/main/java/com/box/sdkgen/serialization/json/JsonManager.java
1
package com.box.sdkgen.serialization.json;
2

3
import com.box.sdkgen.internal.SerializableObject;
4
import com.fasterxml.jackson.annotation.JsonInclude;
5
import com.fasterxml.jackson.core.JsonParser;
6
import com.fasterxml.jackson.core.JsonProcessingException;
7
import com.fasterxml.jackson.core.type.TypeReference;
8
import com.fasterxml.jackson.databind.DeserializationFeature;
9
import com.fasterxml.jackson.databind.JsonNode;
10
import com.fasterxml.jackson.databind.ObjectMapper;
11
import java.io.IOException;
12
import java.net.URLEncoder;
13
import java.util.HashMap;
14
import java.util.Map;
15

16
public class JsonManager {
×
17

18
  public static final ObjectMapper OBJECT_MAPPER =
1✔
19
      new ObjectMapper()
20
          .setSerializationInclusion(JsonInclude.Include.NON_NULL)
1✔
21
          .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
1✔
22

23
  public static JsonNode serialize(Object value) {
24
    return OBJECT_MAPPER.valueToTree(value);
1✔
25
  }
26

27
  public static <T extends SerializableObject> T deserialize(JsonNode content, Class<T> valueType) {
28
    T deserializedObject = OBJECT_MAPPER.convertValue(content, valueType);
1✔
29
    deserializedObject.setRawData(content);
1✔
30
    return deserializedObject;
1✔
31
  }
32

33
  public static JsonNode jsonToSerializedData(String text) {
34
    try {
35
      return OBJECT_MAPPER.readTree(text);
1✔
36
    } catch (JsonProcessingException e) {
1✔
37
      throw new RuntimeException(e);
1✔
38
    }
39
  }
40

41
  public static JsonNode jsonToSerializedData(JsonParser jp) {
42
    try {
43
      return OBJECT_MAPPER.readTree(jp);
1✔
44
    } catch (IOException e) {
×
45
      throw new RuntimeException(e);
×
46
    }
47
  }
48

49
  public static String sdToJson(JsonNode jsonNode) {
50
    return jsonNode.toString();
1✔
51
  }
52

53
  public static String sdToUrlParams(JsonNode jsonNode) {
54
    Map<String, String> map =
1✔
55
        OBJECT_MAPPER.convertValue(jsonNode, new TypeReference<Map<String, String>>() {});
1✔
56
    StringBuilder formData = new StringBuilder();
1✔
57
    for (Map.Entry<String, String> entry : map.entrySet()) {
1✔
58
      if (formData.length() != 0) {
1✔
59
        formData.append('&');
1✔
60
      }
61
      formData.append(URLEncoder.encode(entry.getKey()));
1✔
62
      formData.append('=');
1✔
63
      formData.append(URLEncoder.encode(entry.getValue()));
1✔
64
    }
1✔
65
    return formData.toString();
1✔
66
  }
67

68
  public static String getSdValueByKey(JsonNode jsonNode, String key) {
69
    return jsonNode.get(key).asText();
1✔
70
  }
71

72
  public static String sanitizedValue() {
NEW
73
    return "---[redacted]---";
×
74
  }
75

76
  public static JsonNode sanitizeSerializedData(JsonNode sd, Map<String, String> keysToSanitize) {
NEW
77
    if (!sd.isObject()) {
×
NEW
78
      return sd;
×
79
    }
NEW
80
    Map<String, JsonNode> sanitizedDictionary = new HashMap<>();
×
NEW
81
    sd.fields()
×
NEW
82
        .forEachRemaining(
×
83
            entry -> {
NEW
84
              String key = entry.getKey();
×
NEW
85
              JsonNode value = entry.getValue();
×
NEW
86
              if (keysToSanitize.containsKey(key.toLowerCase()) && value.isTextual()) {
×
NEW
87
                sanitizedDictionary.put(key, new ObjectMapper().valueToTree(sanitizedValue()));
×
NEW
88
              } else if (value.isObject()) {
×
NEW
89
                sanitizedDictionary.put(key, sanitizeSerializedData(value, keysToSanitize));
×
90
              } else {
NEW
91
                sanitizedDictionary.put(key, value);
×
92
              }
NEW
93
            });
×
94

NEW
95
    return new ObjectMapper().valueToTree(sanitizedDictionary);
×
96
  }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc