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

box / box-java-sdk-gen / #254

23 Jun 2025 02:39PM UTC coverage: 34.829% (-0.9%) from 35.719%
#254

push

github

web-flow
feat: add hubs API beta endpoints (box/box-openapi#531) (#341)

36 of 1240 new or added lines in 43 files covered. (2.9%)

7 existing lines in 3 files now uncovered.

16196 of 46502 relevant lines covered (34.83%)

0.35 hits per line

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

83.33
/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() {
UNCOV
73
    return "---[redacted]---";
×
74
  }
75

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

95
    return new ObjectMapper().valueToTree(sanitizedDictionary);
1✔
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