use of org.apache.nifi.registry.bucket.BucketItemType in project nifi-registry by apache.
the class BucketItemDeserializer method deserialize.
@Override
public BucketItem[] deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
final JsonNode arrayNode = jsonParser.getCodec().readTree(jsonParser);
final List<BucketItem> bucketItems = new ArrayList<>();
final Iterator<JsonNode> nodeIter = arrayNode.elements();
while (nodeIter.hasNext()) {
final JsonNode node = nodeIter.next();
final String type = node.get("type").asText();
if (StringUtils.isBlank(type)) {
throw new IllegalStateException("BucketItem type cannot be null or blank");
}
final BucketItemType bucketItemType;
try {
bucketItemType = BucketItemType.valueOf(type);
} catch (Exception e) {
throw new IllegalStateException("Unknown type for BucketItem: " + type, e);
}
switch(bucketItemType) {
case Flow:
final VersionedFlow versionedFlow = jsonParser.getCodec().treeToValue(node, VersionedFlow.class);
bucketItems.add(versionedFlow);
break;
default:
throw new IllegalStateException("Unknown type for BucketItem");
}
}
return bucketItems.toArray(new BucketItem[bucketItems.size()]);
}
Aggregations