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

box / box-java-sdk-gen / #249

23 Jun 2025 12:23PM UTC coverage: 34.749% (-1.0%) from 35.719%
#249

Pull #341

github

web-flow
Merge 463ae8cb1 into 8c4ecda2f
Pull Request #341: feat: add hubs API beta endpoints (box/box-openapi#531)

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

44 existing lines in 9 files now uncovered.

16159 of 46502 relevant lines covered (34.75%)

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

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

UNCOV
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