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

box / box-java-sdk-gen / #286

24 Jun 2025 01:09PM UTC coverage: 35.631% (-0.001%) from 35.632%
#286

push

github

web-flow
fix: Fix Locale Comparison for upperCase and lowerCase (box/box-codegen#746) (#345)

1 of 4 new or added lines in 4 files covered. (25.0%)

3 existing lines in 3 files now uncovered.

16569 of 46502 relevant lines covered (35.63%)

0.36 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.Locale;
15
import java.util.Map;
16

17
public class JsonManager {
×
18

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

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

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

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

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

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

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

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

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

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

96
    return new ObjectMapper().valueToTree(sanitizedDictionary);
×
97
  }
98
}
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