package com.monetate.koupler.format;

import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import org.apache.commons.cli.CommandLine;

/**
 * Created by jpalladino on 8/20/16.
 */
public class JsonFormat implements Format {

    private String partitionKeyField;

    public JsonFormat(CommandLine cmd) {
        if (cmd.hasOption("partitionKeyField")) {
            partitionKeyField = cmd.getOptionValue("partitionKeyField");
        }
    }

    @Override
    public String getPartitionKey(String event) {
        Object jsonEvent = Configuration.defaultConfiguration().jsonProvider().parse(event);
        return JsonPath.read(jsonEvent, partitionKeyField);
    }

    @Override
    public String getData(String event) { return event; }
}

@@ -524,24 +524,102 @@
 ng event) %7B%0A
+        if (event.trim().length() == 0) %7B%0A            return null;%0A        %7D%0A%0A
         Obje

trim leading and trailing whitespace; return null on empty events