Skip to content

Commit 32b16d6

Browse files
committed
feat(json): Improve mapper API
1 parent a66e4eb commit 32b16d6

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

components/json/src/main/java/datadog/json/JsonMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.json;
22

3+
import java.util.Collection;
34
import java.util.Map;
45

56
/** Utility class for simple Java structure mapping into JSON strings. */
@@ -68,8 +69,8 @@ public static String toJson(Map<String, ?> map) {
6869
* @return The converted JSON array as Java string.
6970
*/
7071
@SuppressWarnings("DuplicatedCode")
71-
public static String toJson(Iterable<String> items) {
72-
if (items == null) {
72+
public static String toJson(Collection<String> items) {
73+
if (items == null || items.isEmpty()) {
7374
return "[]";
7475
}
7576
try (JsonWriter writer = new JsonWriter()) {

components/json/src/test/groovy/datadog/json/JsonMapperTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class JsonMapperTest extends Specification {
3232

3333
def "test mapping iterable to JSON array: #input"() {
3434
when:
35-
String json = JsonMapper.toJson((Iterable) input)
35+
String json = JsonMapper.toJson(input as Collection<String>)
3636

3737
then:
3838
json == expected

dd-trace-core/src/main/java/datadog/trace/civisibility/writer/ddintake/CiTestCycleMapperV1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public void accept(Metadata metadata) {
357357
if (!(value instanceof Iterable)) {
358358
writable.writeObjectString(value, null);
359359
} else {
360-
String serializedValue = toJson((Iterable<String>) value);
360+
String serializedValue = toJson((Collection<String>) value);
361361
writable.writeString(serializedValue, null);
362362
}
363363
}

0 commit comments

Comments
 (0)