/*
 * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved.
 * This source code is licensed under the BSD-style license found in the
 * LICENSE.txt file in the root directory of this source tree.
 */
package com.gooddata.util;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;

import java.io.IOException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

import static com.gooddata.util.Validate.notNull;

/**
 * Deserializes whitespace separated tags from one string to set of tags (strings)
 */
public class TagsDeserializer extends JsonDeserializer<Set<String>> {

    @Override
    public Set<String> deserialize(JsonParser jp, DeserializationContext ctx) throws IOException {
        final JsonNode root = jp.readValueAsTree();
        notNull(root, "jsonNode");
        if (root.isTextual()) {
            final Scanner scanner = new Scanner(root.textValue());
            final HashSet<String> tags = new HashSet<>();
            while (scanner.hasNext()) {
                tags.add(scanner.next());
            }
            return tags;
        } else {
            throw new JsonMappingException(jp, "Unknown value of type: " + root.getNodeType(), jp.getCurrentLocation());
        }
    }

}
@@ -1081,54 +1081,45 @@
 nal 
-Scanner scanner = new Scanner(root.textValue()
+HashSet%3CString%3E tags = new HashSet%3C%3E(
 );%0A 
@@ -1133,54 +1133,74 @@
     
+try (
 final 
-HashSet%3CString%3E tags = new HashSet%3C%3E();%0A
+Scanner scanner = new Scanner(root.textValue())) %7B%0A    
     
@@ -1251,16 +1251,20 @@
         
+    
 tags.add
@@ -1277,24 +1277,42 @@
 er.next());%0A
+                %7D%0A
             

handle forgotten closing of Closeable