/*
 *
 *
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *
 *  contributor license agreements. See the NOTICE file distributed with
 *
 *  this work for additional information regarding copyright ownership.
 *
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *
 *  (the "License"); you may not use this file except in compliance with
 *
 *  the License. You may obtain a copy of the License at
 *
 *
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *
 *
 *  Unless required by applicable law or agreed to in writing, software
 *
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 *  See the License for the specific language governing permissions and
 *
 *  limitations under the License.
 *
 * /
 */

package org.apache.kylin.streaming;

import com.google.common.collect.Lists;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.kylin.metadata.model.TblColRef;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * Created by qianzhou on 3/25/15.
 */
public final class JsonStreamParser implements StreamParser {

    private final List<TblColRef> allColumns;

    private static final JsonParser JSON_PARSER = new JsonParser();

    public JsonStreamParser(List<TblColRef> allColumns){
        this.allColumns = allColumns;
    }

    @Override
    public List<String> parse(Stream stream) {
        final JsonObject root = JSON_PARSER.parse(new String(stream.getRawData())).getAsJsonObject();
        ArrayList<String> result = Lists.newArrayList();

        for (TblColRef column : allColumns) {
            for (Map.Entry<String, JsonElement> entry : root.entrySet()) {
                if (entry.getKey().equalsIgnoreCase(column.getName())) {
                    result.add(entry.getValue().getAsString());
                }
            }
        }
        return result;
    }
}

@@ -907,193 +907,331 @@
 com.
-google.common.collect.Lists;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonObject;%0Aimport com.google.gson.JsonParser;%0Aimport org.apache.kylin.metadata.model.TblColRef;%0A
+fasterxml.jackson.databind.ObjectMapper;%0Aimport com.fasterxml.jackson.databind.type.MapType;%0Aimport com.fasterxml.jackson.databind.type.SimpleType;%0Aimport com.google.common.collect.Lists;%0Aimport org.apache.kylin.metadata.model.TblColRef;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.io.IOException;
 %0Aimp
@@ -1276,18 +1276,15 @@
 til.
-Collection
+HashMap
 ;%0Aim
@@ -1449,109 +1449,131 @@
 ate 
-final List%3CTblColRef%3E allColumns;%0A%0A    private static final JsonParser JSON_PARSER = new JsonParser()
+static final Logger logger = LoggerFactory.getLogger(JsonStreamParser.class);%0A%0A    private final List%3CTblColRef%3E allColumns
 ;%0A%0A 
@@ -1746,102 +1746,235 @@
     
-final JsonObject root = JSON_PARSER.parse(new String(stream.getRawData())).getAsJsonObject();%0A
+try %7B%0A            Map%3CString, String%3E json = new ObjectMapper().readValue(%0A                    stream.getRawData(), MapType.construct(HashMap.class, SimpleType.construct(String.class), SimpleType.construct(String.class)));%0A    
     
@@ -2026,25 +2026,24 @@
 List();%0A
-%0A
         
 for (Tbl
@@ -2030,24 +2030,28 @@
 ();%0A        
+    
 for (TblColR
@@ -2084,24 +2084,28 @@
             
+   
+ 
 for (Map.Ent
@@ -2119,19 +2119,14 @@
 ng, 
-JsonElement
+String
 %3E en
@@ -2135,12 +2135,12 @@
 y : 
-root
+json
 .ent
@@ -2146,24 +2146,28 @@
 trySet()) %7B%0A
+    
             
@@ -2247,16 +2247,20 @@
         
+    
 result.a
@@ -2282,25 +2282,15 @@
 ue()
-.getAsString());%0A
+);%0A    
     
@@ -2319,20 +2319,32 @@
     
-%7D%0A    
     %7D%0A
+            %7D%0A    
     
@@ -2366,12 +2366,153 @@
 lt;%0A    
-%7D
+    %7D catch (IOException e) %7B%0A            logger.error(%22error parsing stream%22, e);%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D%0A
 %0A%7D%0A

remove gson dependency