wuchong commented on a change in pull request #11180: [FLINK-16220][json] Fix
JsonRowSerializationSchema cast exception due…
URL: https://github.com/apache/flink/pull/11180#discussion_r393639396
##########
File path:
flink-formats/flink-json/src/test/java/org/apache/flink/formats/json/JsonRowSerializationSchemaTest.java
##########
@@ -113,6 +114,12 @@ public void testNestedSchema() {
assertThat(row, whenSerializedWith(serializationSchema)
.andDeserializedWith(deserializationSchema)
.equalsTo(row));
+
+ row.setField(3, new int[]{1, 2, 3});
+
+ assertThat(row, whenSerializedWith(serializationSchema)
Review comment:
This test can't reproduce the problem. I woudl suggest to have another test,
e.g. (of course, we should add null array into it)
```java
@Test
public void test() throws IOException {
String[] jsons = new String[] {
"{\"svt\":\"2020-02-24T12:58:09.209+0800\"}",
"{\"svt\":\"2020-02-24T12:58:09.209+0800\",
\"ops\":{\"id\":\"281708d0-4092-4c21-9233-931950b6eccf\"}}",
"{\"svt\":\"2020-02-24T12:58:09.209+0800\"}",
};
String[] expected = new String[] {
"{\"svt\":\"2020-02-24T12:58:09.209+0800\",\"ops\":null}",
"{\"svt\":\"2020-02-24T12:58:09.209+0800\",\"ops\":{\"id\":\"281708d0-4092-4c21-9233-931950b6eccf\"}}",
"{\"svt\":\"2020-02-24T12:58:09.209+0800\",\"ops\":null}",
};
TypeInformation<Row> schema = Types.ROW_NAMED(
new String[]{"svt", "ops"},
Types.STRING,
Types.ROW_NAMED(new String[]{"id"}, Types.STRING));
JsonRowDeserializationSchema deserializationSchema = new
JsonRowDeserializationSchema.Builder(schema)
.build();
JsonRowSerializationSchema serializationSchema =
JsonRowSerializationSchema.builder()
.withTypeInfo(schema)
.build();
for (int i = 0; i < jsons.length; i++) {
String json = jsons[i];
Row row =
deserializationSchema.deserialize(json.getBytes());
String result = new
String(serializationSchema.serialize(row));
assertEquals(expected[i], result);
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services