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

box / box-java-sdk / #5925

17 Dec 2025 05:03PM UTC coverage: 35.453% (-0.1%) from 35.558%
#5925

push

github

web-flow
fix: add taxonomy to Metadata Field (read) definition (box/box-openapi#572) (#1644)

Co-authored-by: box-sdk-build <box-sdk-build@box.com>

2 of 2 new or added lines in 1 file covered. (100.0%)

62 existing lines in 13 files now uncovered.

18901 of 53313 relevant lines covered (35.45%)

0.35 hits per line

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

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

3
import com.box.sdkgen.internal.NullablePropertyFilter;
4
import com.box.sdkgen.internal.SerializableObject;
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 com.fasterxml.jackson.databind.ObjectWriter;
12
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
13
import com.fasterxml.jackson.databind.util.TokenBuffer;
14
import java.io.IOException;
15
import java.net.URLEncoder;
16
import java.util.HashMap;
17
import java.util.Locale;
18
import java.util.Map;
19

20
public class JsonManager {
×
21

22
  public static final ObjectMapper OBJECT_MAPPER =
1✔
23
      new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
1✔
24

25
  public static final SimpleFilterProvider EXPLICITLY_SET_FILTERS =
1✔
26
      new SimpleFilterProvider()
27
          .addFilter("nullablePropertyFilter", new NullablePropertyFilter())
1✔
28
          .setFailOnUnknownId(false);
1✔
29

30
  public static final ObjectWriter WRITER = OBJECT_MAPPER.writer(EXPLICITLY_SET_FILTERS);
1✔
31

32
  public static JsonNode serialize(Object value) {
33
    try {
34
      TokenBuffer tokenBuffer = new TokenBuffer(OBJECT_MAPPER, false);
1✔
35
      WRITER.writeValue(tokenBuffer, value);
1✔
36

37
      JsonNode node = tokenBuffer.asParser().readValueAsTree();
1✔
38
      tokenBuffer.close();
1✔
39

40
      return node;
1✔
41
    } catch (IOException e) {
×
42
      throw new RuntimeException(e);
×
43
    }
44
  }
45

46
  public static <T extends SerializableObject> T deserialize(JsonNode content, Class<T> valueType) {
47
    T deserializedObject = OBJECT_MAPPER.convertValue(content, valueType);
1✔
48
    deserializedObject.setRawData(content);
1✔
49
    return deserializedObject;
1✔
50
  }
51

52
  public static JsonNode jsonToSerializedData(String text) {
53
    try {
54
      return OBJECT_MAPPER.readTree(text);
1✔
55
    } catch (JsonProcessingException e) {
1✔
56
      throw new RuntimeException(e);
1✔
57
    }
58
  }
59

60
  public static JsonNode jsonToSerializedData(JsonParser jp) {
61
    try {
62
      return OBJECT_MAPPER.readTree(jp);
1✔
63
    } catch (IOException e) {
×
64
      throw new RuntimeException(e);
×
65
    }
66
  }
67

68
  public static String sdToJson(JsonNode jsonNode) {
69
    return jsonNode.toString();
1✔
70
  }
71

72
  public static String sdToUrlParams(JsonNode jsonNode) {
73
    Map<String, String> map =
1✔
74
        OBJECT_MAPPER.convertValue(jsonNode, new TypeReference<Map<String, String>>() {});
1✔
75
    StringBuilder formData = new StringBuilder();
1✔
76
    for (Map.Entry<String, String> entry : map.entrySet()) {
1✔
77
      if (formData.length() != 0) {
1✔
78
        formData.append('&');
1✔
79
      }
80
      formData.append(URLEncoder.encode(entry.getKey()));
1✔
81
      formData.append('=');
1✔
82
      formData.append(URLEncoder.encode(entry.getValue()));
1✔
83
    }
1✔
84
    return formData.toString();
1✔
85
  }
86

87
  public static String getSdValueByKey(JsonNode jsonNode, String key) {
88
    return jsonNode.get(key).asText();
1✔
89
  }
90

91
  public static String sanitizedValue() {
UNCOV
92
    return "---[redacted]---";
×
93
  }
94

95
  public static JsonNode sanitizeSerializedData(JsonNode sd, Map<String, String> keysToSanitize) {
UNCOV
96
    if (sd == null || !sd.isObject()) {
×
97
      return sd;
×
98
    }
UNCOV
99
    Map<String, JsonNode> sanitizedDictionary = new HashMap<>();
×
UNCOV
100
    sd.fields()
×
UNCOV
101
        .forEachRemaining(
×
102
            entry -> {
UNCOV
103
              String key = entry.getKey();
×
UNCOV
104
              JsonNode value = entry.getValue();
×
UNCOV
105
              if (keysToSanitize.containsKey(key.toLowerCase(Locale.ROOT)) && value.isTextual()) {
×
106
                sanitizedDictionary.put(key, new ObjectMapper().valueToTree(sanitizedValue()));
×
UNCOV
107
              } else if (value.isObject()) {
×
108
                sanitizedDictionary.put(key, sanitizeSerializedData(value, keysToSanitize));
×
109
              } else {
UNCOV
110
                sanitizedDictionary.put(key, value);
×
111
              }
UNCOV
112
            });
×
113

UNCOV
114
    return new ObjectMapper().valueToTree(sanitizedDictionary);
×
115
  }
116
}
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

© 2025 Coveralls, Inc