Skip to content

Commit

Permalink
Merge pull request #1260 from microsoft/andrueastman/validateMultiDim…
Browse files Browse the repository at this point in the history
…ensionalArrays

Validates multidimensional collections scenarios using UntypedNode
  • Loading branch information
andrueastman authored May 6, 2024
2 parents 4aa3555 + 1272c4e commit 39d3930
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class JsonParseNodeTests {
+ " }\r\n"
+ " ],\r\n"
+ " \"detail\": null,\r\n"
+ " \"table\": [[1,2,3],[4,5,6],[7,8,9]],\r\n"
+ " \"extra\": {\r\n"
+ " \"createdDateTime\":\"2024-01-15T00:00:00\\u002B00:00\"\r\n"
+ " }\r\n"
Expand Down Expand Up @@ -160,5 +161,15 @@ void GetEntityWithUntypedNodesFromJson() throws UnsupportedEncodingException {
assertNull(entity.getDetail());
var extra = entity.getAdditionalData().get("extra");
assertNotNull(extra);
assertNotNull(entity.getTable());
var table = (UntypedArray) entity.getTable(); // the table is a collection
for (var value : table.getValue()) {
var row = (UntypedArray) value;
assertNotNull(row); // The values are a nested collection
for (var item : row.getValue()) {
var rowItem = (UntypedDouble) item;
assertNotNull(rowItem); // The values are UntypedInteger
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public void setDetail(UntypedNode _detail) {
this._detail = _detail;
}

private UntypedNode _table;

public UntypedNode getTable() {
return _table;
}

public void setTable(UntypedNode _table) {
this._table = _table;
}

@Override
public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
return new HashMap<>() {
Expand All @@ -76,6 +86,11 @@ public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
(n) -> {
setDetail(n.getObjectValue(UntypedNode::createFromDiscriminatorValue));
});
put(
"table",
(n) -> {
setTable(n.getObjectValue(UntypedNode::createFromDiscriminatorValue));
});
}
};
}
Expand All @@ -87,6 +102,7 @@ public void serialize(SerializationWriter writer) {
writer.writeObjectValue("location", getLocation());
writer.writeObjectValue("keywords", getKeywords());
writer.writeObjectValue("detail", getDetail());
writer.writeObjectValue("table", getDetail());
writer.writeAdditionalData(getAdditionalData());
}

Expand Down

0 comments on commit 39d3930

Please sign in to comment.