json Файл:
{
"id": 1,
"name": "TC1",
"steps": [
{
"stepId": 1,
"action": "open",
"object": "chrome",
"input": "https://www.google.com/",
}
]
}
и код java:
public static void updateTestCaseValue(String tabTCPath) {
ObjectMapper objectMapper = new ObjectMapper();
File jsonFile = new File(tabTCPath);
try {
JsonNode arrNode = objectMapper.readTree(jsonFile).get("steps");
if (arrNode.isArray()) {
for (final JsonNode objNode : arrNode) {
if(objNode.findPath("stepId").asText().equals("1")) {
((ObjectNode) objNode).put("object", "Firefox");
}
objectMapper.writerWithDefaultPrettyPrinter().writeValue(new File(tabTCPath), arrNode);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
И вывод:
[ {
"stepId" : 1,
"action" : "openBrowser1",
"object" : "Firefox",
"input" : "https://www.google.com/",
"output" : "",
"description" : "Open browser"
}]
, но нижняя часть не записывается вфайл
"id": 1,
"name": "TC1",