|
34 | 34 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException; |
35 | 35 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode; |
36 | 36 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper; |
| 37 | +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.JsonNodeType; |
37 | 38 | import org.apache.flink.streaming.connectors.kafka.internal.KafkaConsumerThread; |
38 | 39 | import org.apache.flink.streaming.connectors.kafka.internals.AbstractFetcher; |
39 | 40 | import org.apache.flink.types.Row; |
@@ -124,7 +125,7 @@ public Row deserialize(byte[] message) { |
124 | 125 | Row row = new Row(fieldNames.length); |
125 | 126 |
|
126 | 127 | for (int i = 0; i < fieldNames.length; i++) { |
127 | | - JsonNode node = getIgnoreCase(root, fieldNames[i]); |
| 128 | + JsonNode node = getIgnoreCase(fieldNames[i]); |
128 | 129 |
|
129 | 130 | if (node == null) { |
130 | 131 | if (failOnMissingField) { |
@@ -168,9 +169,16 @@ public void setFailOnMissingField(boolean failOnMissingField) { |
168 | 169 | } |
169 | 170 |
|
170 | 171 |
|
171 | | - public JsonNode getIgnoreCase(JsonNode jsonNode, String key) { |
| 172 | + public JsonNode getIgnoreCase(String key) { |
172 | 173 | String nodeMappingKey = rowAndFieldMapping.get(key); |
173 | | - return nodeAndJsonnodeMapping.get(nodeMappingKey); |
| 174 | + JsonNode node = nodeAndJsonnodeMapping.get(nodeMappingKey); |
| 175 | + JsonNodeType nodeType = node.getNodeType(); |
| 176 | + |
| 177 | + if (nodeType==JsonNodeType.ARRAY){ |
| 178 | + throw new IllegalStateException("Unsupported type information array .") ; |
| 179 | + } |
| 180 | + |
| 181 | + return node; |
174 | 182 | } |
175 | 183 |
|
176 | 184 | public void setFetcher(AbstractFetcher<Row, ?> fetcher) { |
@@ -236,12 +244,7 @@ private Object convert(JsonNode node, TypeInformation<?> info) { |
236 | 244 | } else if (info.getTypeClass().equals(Types.SQL_TIMESTAMP.getTypeClass())) { |
237 | 245 | // local zone |
238 | 246 | return Timestamp.valueOf(node.asText()); |
239 | | - } else if (info instanceof ObjectArrayTypeInfo) { |
240 | | - throw new IllegalStateException("Unsupported type information '" + info + "' for node: " + node); |
241 | | - } else if (info instanceof BasicArrayTypeInfo) { |
242 | | - throw new IllegalStateException("Unsupported type information '" + info + "' for node: " + node); |
243 | | - } else if (info instanceof PrimitiveArrayTypeInfo && |
244 | | - ((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) { |
| 247 | + } else if (info.getTypeClass().equals(Types.BYTE.getTypeClass())){ |
245 | 248 | return convertByteArray(node); |
246 | 249 | } else { |
247 | 250 | // for types that were specified without JSON schema |
|
0 commit comments