Skip to content

Commit 23b0ecf

Browse files
committed
Merge branch 'master' into ygree/servicetalk-concurrent-instrumentation-0.42.56
2 parents 9a61436 + 7c80dbe commit 23b0ecf

File tree

75 files changed

+1519
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1519
-371
lines changed

.github/workflows/update-docker-build-image.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
sed -i 's|DOCKER_IMAGE_VERSION=.*|DOCKER_IMAGE_VERSION="${{ steps.define-tag.outputs.tag }}"|' .circleci/render_config.py
5656
- name: Update the Docker build image in GitLab CI config
5757
run: |
58-
sed -i 's|image: ghcr.io/datadog/dd-trace-java-docker-build:.*|image: ghcr.io/datadog/dd-trace-java-docker-build:${{ steps.define-tag.outputs.tag }}-base|' .gitlab-ci.yml
58+
sed -i 's|JAVA_BUILD_IMAGE_VERSION:.*|JAVA_BUILD_IMAGE_VERSION:"${{ steps.define-tag.outputs.tag }}"|' .gitlab-ci.yml
5959
- name: Commit and push changes
6060
env:
6161
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

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

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

3+
import static java.util.Collections.emptyList;
4+
import static java.util.Collections.emptyMap;
5+
6+
import java.io.IOException;
7+
import java.util.ArrayList;
38
import java.util.Collection;
9+
import java.util.List;
410
import java.util.Map;
511

612
/** Utility class for simple Java structure mapping into JSON strings. */
@@ -103,4 +109,47 @@ public static String toJson(String[] items) {
103109
return writer.toString();
104110
}
105111
}
112+
113+
/**
114+
* Parses a JSON string into a {@link Map}.
115+
*
116+
* @param json The JSON string to parse.
117+
* @return A {@link Map} containing the parsed JSON object's key-value pairs.
118+
* @throws IOException If the JSON is invalid or a reader error occurs.
119+
*/
120+
@SuppressWarnings("unchecked")
121+
public static Map<String, Object> fromJsonToMap(String json) throws IOException {
122+
if (json == null || json.isEmpty() || "{}".equals(json) || "null".equals(json)) {
123+
return emptyMap();
124+
}
125+
try (JsonReader reader = new JsonReader(json)) {
126+
Object value = reader.nextValue();
127+
if (!(value instanceof Map)) {
128+
throw new IOException("Expected JSON object but was " + value.getClass().getSimpleName());
129+
}
130+
return (Map<String, Object>) value;
131+
}
132+
}
133+
134+
/**
135+
* Parses a JSON string array into a {@link List<String>}.
136+
*
137+
* @param json The JSON string array to parse.
138+
* @return A {@link List<String>} containing the parsed JSON strings.
139+
* @throws IOException If the JSON is invalid or a reader error occurs.
140+
*/
141+
public static List<String> fromJsonToList(String json) throws IOException {
142+
if (json == null || json.isEmpty() || "[]".equals(json) || "null".equals(json)) {
143+
return emptyList();
144+
}
145+
try (JsonReader reader = new JsonReader(json)) {
146+
List<String> list = new ArrayList<>();
147+
reader.beginArray();
148+
while (reader.hasNext()) {
149+
list.add(reader.nextString());
150+
}
151+
reader.endArray();
152+
return list;
153+
}
154+
}
106155
}

0 commit comments

Comments
 (0)