[Monitor Server] Format results in List<JsonNode>#35
Conversation
Signed-off-by: Thang PHAM <phamthang37@gmail.com>
📝 WalkthroughWalkthroughThe MonitorController was modified to deserialize string-based execution results into JSON nodes. Jackson dependencies were introduced, the constructor now accepts an ObjectMapper, and the getExecutionResults method's return type changed from List to List, with per-item parsing and error handling added. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/MonitorController.java`:
- Around line 74-80: The error message in MonitorController is misleading and
nulls can cause NPEs: change the exception text in the objectMapper.readValue
handler to say "Unable to deserialize result from JSON: <resultString>" (or
similar) and guard against null entries from results before calling readValue;
e.g., filter the results stream with Objects::nonNull or add an explicit null
check in the lambda so nulls are handled (throw a clear IllegalStateException
like "Result is null" or skip them), referencing the results variable, the
objectMapper.readValue(...) call, and the lambda in the stream.
| List<JsonNode> resultsJsonNode = results.stream().map(resultString -> { | ||
| try { | ||
| return objectMapper.readValue(resultString, JsonNode.class); | ||
| } catch (JsonProcessingException e) { | ||
| throw new IllegalStateException(String.format("Unable to serialize result to JSON: %s", resultString), e); | ||
| } | ||
| }).toList(); |
There was a problem hiding this comment.
Error message incorrectly says "serialize" instead of "deserialize".
The operation readValue is deserialization (parsing JSON string to object), not serialization. Additionally, if resultString is null, this will throw a NullPointerException rather than the expected JsonProcessingException.
Proposed fix
List<JsonNode> resultsJsonNode = results.stream().map(resultString -> {
try {
return objectMapper.readValue(resultString, JsonNode.class);
} catch (JsonProcessingException e) {
- throw new IllegalStateException(String.format("Unable to serialize result to JSON: %s", resultString), e);
+ throw new IllegalStateException(String.format("Unable to deserialize result from JSON: %s", resultString), e);
}
}).toList();If null results are possible from monitorService.getResults(), consider filtering them out or handling explicitly:
List<JsonNode> resultsJsonNode = results.stream()
.filter(Objects::nonNull)
.map(resultString -> { ... })
.toList();🤖 Prompt for AI Agents
In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/MonitorController.java`
around lines 74 - 80, The error message in MonitorController is misleading and
nulls can cause NPEs: change the exception text in the objectMapper.readValue
handler to say "Unable to deserialize result from JSON: <resultString>" (or
similar) and guard against null entries from results before calling readValue;
e.g., filter the results stream with Objects::nonNull or add an explicit null
check in the lambda so nulls are handled (throw a clear IllegalStateException
like "Result is null" or skip them), referencing the results variable, the
objectMapper.readValue(...) call, and the lambda in the stream.
PR Summary
List<JsonNode>.