{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/comments/64552819","id":64552819,"diff_hunk":"@@ -0,0 +1,451 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *   http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+package com.datatorrent.contrib.parser;\n+\n+import java.io.UnsupportedEncodingException;\n+import java.util.ArrayList;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.ListIterator;\n+import java.util.StringTokenizer;\n+\n+import org.elasticsearch.common.primitives.Ints;\n+import org.json.simple.parser.JSONParser;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import org.apache.commons.lang3.ClassUtils;\n+import org.apache.hadoop.classification.InterfaceStability;\n+\n+import com.google.common.collect.Lists;\n+\n+import com.datatorrent.api.Context;\n+import com.datatorrent.api.Context.OperatorContext;\n+import com.datatorrent.api.Context.PortContext;\n+import com.datatorrent.api.DefaultOutputPort;\n+import com.datatorrent.api.annotation.OutputPortFieldAnnotation;\n+import com.datatorrent.lib.parser.Parser;\n+import com.datatorrent.lib.util.FieldInfo;\n+import com.datatorrent.lib.util.FieldInfo.SupportType;\n+import com.datatorrent.lib.util.KeyValPair;\n+import com.datatorrent.lib.util.PojoUtils;\n+\n+/**\n+ * Operator that parses a JSON string tuple and emits a POJO on the output port\n+ * and tuples that could not be parsed on error port.Upstream operator needs to\n+ * ensure that a full JSON record is emitted.<br>\n+ * <b>Properties</b><br>\n+ * <b>pojoClass</b>:POJO class <br>\n+ * <b>(optional)fieldMappingString</b>String of format\n+ * fieldNameInJson:fieldNameInPOJO:DataType<br>\n+ * <b>Ports</b> <br>\n+ * <b>in</b>:input tuple as a String. Each tuple represents a json string<br>\n+ * <b>out</b>:tuples that are validated as per the user defined POJO are emitted\n+ * as POJO on this port<br>\n+ * <b>err</b>:tuples that could not be parsed are emitted on this port as\n+ * KeyValPair<String,String><br>\n+ * Key being the tuple and Val being the reason\n+ * \n+ * @displayName SimpleStreamingJsonParser\n+ * @category Parsers\n+ * @tags json pojo parser streaming\n+ */\n+@InterfaceStability.Evolving\n+public class StreamingJsonParser extends Parser<byte[], KeyValPair<String, String>>\n+{\n+  private String jsonSchema;\n+  private transient JSONParser jsonParser;\n+  private String fieldMappingString;\n+  private List<FieldInfo> fieldInfos;\n+  private List<ActiveFieldInfo> columnFieldSetters;\n+  protected JsonKeyFinder finder;\n+  private static final String FIELD_SEPARATOR = \":\";\n+  private static final String RECORD_SEPARATOR = \",\";\n+  private ArrayList<String> columnFields;\n+  private transient Class<?> pojoClass;\n+\n+  /**\n+   * @return POJO class\n+   */\n+  private Class<?> getPojoClass()\n+  {\n+    return pojoClass;\n+  }\n+\n+  /**\n+   * Sets the POJO class\n+   */\n+  public void setPojoClass(Class<?> pojoClass)\n+  {\n+    this.pojoClass = pojoClass;\n+  }\n+\n+  /**\n+   * Returns a string representing mapping from generic record to POJO fields\n+   */\n+  public String getFieldMappingString()\n+  {\n+    return fieldMappingString;\n+  }\n+\n+  /**\n+   * Comma separated list mapping a field in JSON schema to POJO field eg :\n+   * fieldName:INTEGER,fieldName:DOUBLE\n+   */\n+  public void setFieldMappingString(String genericRecordToPOJOFieldsMapping)\n+  {\n+    this.fieldMappingString = genericRecordToPOJOFieldsMapping;\n+  }\n+\n+  public String getJsonSchema()\n+  {\n+    return jsonSchema;\n+  }\n+\n+  public void setJsonSchema(String jsonSchema)\n+  {\n+    this.jsonSchema = jsonSchema;\n+  }\n+\n+  public StreamingJsonParser()\n+  {\n+\n+  }\n+\n+  @Override\n+  public void setup(OperatorContext context)\n+  {\n+    jsonParser = new JSONParser();\n+    finder = new JsonKeyFinder();\n+    columnFields = new ArrayList<String>();\n+    columnFieldSetters = Lists.newArrayList();\n+\n+    //use reflection if POJO to JSON key mapping is missing\n+    if (getFieldMappingString() == null) {\n+      setFieldInfos(createFieldInfoMap(generateFieldInfoInputs(getPojoClass())));","path":"contrib/src/main/java/com/datatorrent/contrib/parser/StreamingJsonParser.java","position":141,"original_position":141,"commit_id":"4a61de8e02e75b3d9637cf37953f476d7493d81d","original_commit_id":"4a61de8e02e75b3d9637cf37953f476d7493d81d","user":{"login":"shubham-pathak22","id":3529753,"avatar_url":"https://avatars.githubusercontent.com/u/3529753?v=3","gravatar_id":"","url":"https://api.github.com/users/shubham-pathak22","html_url":"https://github.com/shubham-pathak22","followers_url":"https://api.github.com/users/shubham-pathak22/followers","following_url":"https://api.github.com/users/shubham-pathak22/following{/other_user}","gists_url":"https://api.github.com/users/shubham-pathak22/gists{/gist_id}","starred_url":"https://api.github.com/users/shubham-pathak22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shubham-pathak22/subscriptions","organizations_url":"https://api.github.com/users/shubham-pathak22/orgs","repos_url":"https://api.github.com/users/shubham-pathak22/repos","events_url":"https://api.github.com/users/shubham-pathak22/events{/privacy}","received_events_url":"https://api.github.com/users/shubham-pathak22/received_events","type":"User","site_admin":false},"body":"Class is available after the setup method of output port is called. I suggest inititilazing fieldInfos in setup method of output port. ( similar to [AvroToPojo](https://github.com/apache/incubator-apex-malhar/blob/master/contrib/src/main/java/com/datatorrent/contrib/avro/AvroToPojo.java) )","created_at":"2016-05-25T10:57:18Z","updated_at":"2016-05-25T10:57:18Z","html_url":"https://github.com/apache/incubator-apex-malhar/pull/288#discussion_r64552819","pull_request_url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/288","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/comments/64552819"},"html":{"href":"https://github.com/apache/incubator-apex-malhar/pull/288#discussion_r64552819"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/288"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/288","id":71314170,"html_url":"https://github.com/apache/incubator-apex-malhar/pull/288","diff_url":"https://github.com/apache/incubator-apex-malhar/pull/288.diff","patch_url":"https://github.com/apache/incubator-apex-malhar/pull/288.patch","issue_url":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/288","number":288,"state":"open","locked":false,"title":"Apexmalhar 2033 streaming parser","user":{"login":"devtagare","id":7666415,"avatar_url":"https://avatars.githubusercontent.com/u/7666415?v=3","gravatar_id":"","url":"https://api.github.com/users/devtagare","html_url":"https://github.com/devtagare","followers_url":"https://api.github.com/users/devtagare/followers","following_url":"https://api.github.com/users/devtagare/following{/other_user}","gists_url":"https://api.github.com/users/devtagare/gists{/gist_id}","starred_url":"https://api.github.com/users/devtagare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devtagare/subscriptions","organizations_url":"https://api.github.com/users/devtagare/orgs","repos_url":"https://api.github.com/users/devtagare/repos","events_url":"https://api.github.com/users/devtagare/events{/privacy}","received_events_url":"https://api.github.com/users/devtagare/received_events","type":"User","site_admin":false},"body":"Streaming JSON parser","created_at":"2016-05-25T00:28:10Z","updated_at":"2016-05-25T10:57:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0c10afe1503f7a9e3950c0caa443f40ddbe3fa84","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/288/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/288/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/288/comments","statuses_url":"https://api.github.com/repos/apache/incubator-apex-malhar/statuses/4a61de8e02e75b3d9637cf37953f476d7493d81d","head":{"label":"devtagare:APEXMALHAR-2033-StreamingParser","ref":"APEXMALHAR-2033-StreamingParser","sha":"4a61de8e02e75b3d9637cf37953f476d7493d81d","user":{"login":"devtagare","id":7666415,"avatar_url":"https://avatars.githubusercontent.com/u/7666415?v=3","gravatar_id":"","url":"https://api.github.com/users/devtagare","html_url":"https://github.com/devtagare","followers_url":"https://api.github.com/users/devtagare/followers","following_url":"https://api.github.com/users/devtagare/following{/other_user}","gists_url":"https://api.github.com/users/devtagare/gists{/gist_id}","starred_url":"https://api.github.com/users/devtagare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devtagare/subscriptions","organizations_url":"https://api.github.com/users/devtagare/orgs","repos_url":"https://api.github.com/users/devtagare/repos","events_url":"https://api.github.com/users/devtagare/events{/privacy}","received_events_url":"https://api.github.com/users/devtagare/received_events","type":"User","site_admin":false},"repo":{"id":53950635,"name":"incubator-apex-malhar","full_name":"devtagare/incubator-apex-malhar","owner":{"login":"devtagare","id":7666415,"avatar_url":"https://avatars.githubusercontent.com/u/7666415?v=3","gravatar_id":"","url":"https://api.github.com/users/devtagare","html_url":"https://github.com/devtagare","followers_url":"https://api.github.com/users/devtagare/followers","following_url":"https://api.github.com/users/devtagare/following{/other_user}","gists_url":"https://api.github.com/users/devtagare/gists{/gist_id}","starred_url":"https://api.github.com/users/devtagare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devtagare/subscriptions","organizations_url":"https://api.github.com/users/devtagare/orgs","repos_url":"https://api.github.com/users/devtagare/repos","events_url":"https://api.github.com/users/devtagare/events{/privacy}","received_events_url":"https://api.github.com/users/devtagare/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/devtagare/incubator-apex-malhar","description":"Mirror of Apache Apex malhar (Incubating)","fork":true,"url":"https://api.github.com/repos/devtagare/incubator-apex-malhar","forks_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/forks","keys_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/teams","hooks_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/hooks","issue_events_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/issues/events{/number}","events_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/events","assignees_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/assignees{/user}","branches_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/branches{/branch}","tags_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/tags","blobs_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/git/refs{/sha}","trees_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/statuses/{sha}","languages_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/languages","stargazers_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/stargazers","contributors_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/contributors","subscribers_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/subscribers","subscription_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/subscription","commits_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/commits{/sha}","git_commits_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/git/commits{/sha}","comments_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/comments{/number}","issue_comment_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/issues/comments{/number}","contents_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/contents/{+path}","compare_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/merges","archive_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/downloads","issues_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/issues{/number}","pulls_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/pulls{/number}","milestones_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/milestones{/number}","notifications_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/labels{/name}","releases_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/releases{/id}","deployments_url":"https://api.github.com/repos/devtagare/incubator-apex-malhar/deployments","created_at":"2016-03-15T14:20:54Z","updated_at":"2016-03-15T14:20:59Z","pushed_at":"2016-05-25T00:26:54Z","git_url":"git://github.com/devtagare/incubator-apex-malhar.git","ssh_url":"git@github.com:devtagare/incubator-apex-malhar.git","clone_url":"https://github.com/devtagare/incubator-apex-malhar.git","svn_url":"https://github.com/devtagare/incubator-apex-malhar","homepage":null,"size":85438,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"9c11400a21fe78c1709933293dea9cad1490f887","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":41348334,"name":"incubator-apex-malhar","full_name":"apache/incubator-apex-malhar","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-apex-malhar","description":"Mirror of Apache Apex malhar (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-apex-malhar","forks_url":"https://api.github.com/repos/apache/incubator-apex-malhar/forks","keys_url":"https://api.github.com/repos/apache/incubator-apex-malhar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-apex-malhar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-apex-malhar/teams","hooks_url":"https://api.github.com/repos/apache/incubator-apex-malhar/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-apex-malhar/events","assignees_url":"https://api.github.com/repos/apache/incubator-apex-malhar/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-apex-malhar/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-apex-malhar/tags","blobs_url":"https://api.github.com/repos/apache/incubator-apex-malhar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-apex-malhar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-apex-malhar/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-apex-malhar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-apex-malhar/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-apex-malhar/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-apex-malhar/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-apex-malhar/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-apex-malhar/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-apex-malhar/subscription","commits_url":"https://api.github.com/repos/apache/incubator-apex-malhar/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-apex-malhar/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-apex-malhar/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-apex-malhar/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-apex-malhar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-apex-malhar/merges","archive_url":"https://api.github.com/repos/apache/incubator-apex-malhar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-apex-malhar/downloads","issues_url":"https://api.github.com/repos/apache/incubator-apex-malhar/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-apex-malhar/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-apex-malhar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-apex-malhar/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-apex-malhar/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-apex-malhar/deployments","created_at":"2015-08-25T07:00:05Z","updated_at":"2016-05-17T17:10:48Z","pushed_at":"2016-05-25T00:28:10Z","git_url":"git://github.com/apache/incubator-apex-malhar.git","ssh_url":"git@github.com:apache/incubator-apex-malhar.git","clone_url":"https://github.com/apache/incubator-apex-malhar.git","svn_url":"https://github.com/apache/incubator-apex-malhar","homepage":null,"size":96103,"stargazers_count":34,"watchers_count":34,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":71,"mirror_url":"git://git.apache.org/incubator-apex-malhar.git","open_issues_count":12,"forks":71,"open_issues":12,"watchers":34,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/288"},"html":{"href":"https://github.com/apache/incubator-apex-malhar/pull/288"},"issue":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/288"},"comments":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/issues/288/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/288/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/pulls/288/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-apex-malhar/statuses/4a61de8e02e75b3d9637cf37953f476d7493d81d"}}}}
{"actor":{"display_login":"shubham-pathak22"}}