{"action":"created","comment":{"url":"https://api.github.com/repos/wso2/siddhi/pulls/comments/216215573","pull_request_review_id":153644784,"id":216215573,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNjIxNTU3Mw==","diff_hunk":"@@ -0,0 +1,498 @@\n+/*\n+ * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.\n+ *\n+ * WSO2 Inc. licenses this file to you under the Apache License,\n+ * Version 2.0 (the \"License\"); you may not use this file except\n+ * in compliance with the License.\n+ * 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 org.wso2.siddhi.extension.input.mapper.json;\n+\n+import com.fasterxml.jackson.core.JsonFactory;\n+import com.fasterxml.jackson.core.JsonParser;\n+import com.fasterxml.jackson.core.JsonToken;\n+import com.google.gson.Gson;\n+import com.google.gson.JsonObject;\n+import com.jayway.jsonpath.Configuration;\n+import com.jayway.jsonpath.JsonPath;\n+import com.jayway.jsonpath.PathNotFoundException;\n+import com.jayway.jsonpath.ReadContext;\n+import net.minidev.json.JSONArray;\n+\n+import org.apache.log4j.Logger;\n+import org.wso2.siddhi.annotation.Example;\n+import org.wso2.siddhi.annotation.Extension;\n+import org.wso2.siddhi.annotation.Parameter;\n+import org.wso2.siddhi.annotation.util.DataType;\n+import org.wso2.siddhi.core.event.Event;\n+import org.wso2.siddhi.core.exception.ExecutionPlanRuntimeException;\n+import org.wso2.siddhi.core.stream.AttributeMapping;\n+import org.wso2.siddhi.core.stream.input.InputEventHandler;\n+import org.wso2.siddhi.core.stream.input.source.SourceMapper;\n+import org.wso2.siddhi.core.util.AttributeConverter;\n+import org.wso2.siddhi.core.util.config.ConfigReader;\n+import org.wso2.siddhi.core.util.transport.OptionHolder;\n+import org.wso2.siddhi.query.api.definition.Attribute;\n+import org.wso2.siddhi.query.api.definition.StreamDefinition;\n+\n+import java.io.IOException;\n+import java.util.ArrayList;\n+import java.util.Arrays;\n+import java.util.List;\n+\n+/**\n+ * This mapper converts JSON string input to {@link org.wso2.siddhi.core.event.ComplexEventChunk}.\n+ * This extension accepts optional json path expressions to\n+ * select specific attributes from the stream.\n+ */\n+\n+@Extension(\n+        name = \"json\",\n+        namespace = \"sourceMapper\",\n+        description = \"JSON to Event input mapper. Transports which accepts JSON messages can utilize this extension\"\n+                + \"to convert the incoming JSON message to Siddhi event. Users can either send a pre-defined JSON \"\n+                + \"format where event conversion will happen without any configs or can use json path to map from a \"\n+                + \"custom JSON message.\",\n+        parameters = {\n+                @Parameter(name = \"enclosing.element\",\n+                        description =\n+                                \"Used to specify the enclosing element in case of sending multiple events in same \"\n+                                        + \"JSON message. WSO2 DAS will treat the child element of given enclosing \"\n+                                        + \"element as events\"\n+                                        + \" and execute json path expressions on child elements. If enclosing.element \"\n+                                        + \"is not provided \"\n+                                        + \"multiple event scenario is disregarded and json path will be evaluated \"\n+                                        + \"with respect to \"\n+                                        + \"root element.\",\n+                        type = {DataType.STRING}),\n+                @Parameter(name = \"fail.on.missing.attribute\",\n+                        description = \"This can either have value true or false. By default it will be true. This \"\n+                                + \"attribute allows user to handle unknown attributes. By default if an json \"\n+                                + \"execution \"\n+                                + \"fails or returns null DAS will drop that message. However setting this property\"\n+                                + \" to \"\n+                                + \"false will prompt DAS to send and event with null value to Siddhi where user \"\n+                                + \"can handle\"\n+                                + \" it accordingly(ie. Assign a default value)\",\n+                        type = {DataType.BOOL})\n+        },\n+        examples = {\n+                @Example(\n+                        syntax = \"@source(type='inMemory', topic='stock', @map(type='json'))\\n\"\n+                                + \"define stream FooStream (symbol string, price float, volume long);\\n\",\n+                        description =  \"Above configuration will do a default JSON input mapping. Expected \"\n+                                + \"input will look like below.\"\n+                                + \"{\\n\"\n+                                + \"    \\\"event\\\":{\\n\"\n+                                + \"        \\\"symbol\\\":\\\"WSO2\\\",\\n\"\n+                                + \"        \\\"price\\\":55.6,\\n\"\n+                                + \"        \\\"volume\\\":100\\n\"\n+                                + \"    }\\n\"\n+                                + \"}\\n\"),\n+                @Example(\n+                        syntax = \"@source(type='inMemory', topic='stock', @map(type='json', \"\n+                                + \"enclosing.element=\\\"$.portfolio\\\", \"\n+                                + \"@attributes(symbol = \\\"company.symbol\\\", price = \\\"price\\\", volume = \\\"volume\\\")))\",\n+                        description =  \"Above configuration will perform a custom JSON mapping. Expected input will \"\n+                                + \"look like below.\"\n+                                + \"{\"\n+                                + \" \\\"portfolio\\\":{\\n\"\n+                                + \"     \\\"stock\\\":{\"\n+                                + \"        \\\"volume\\\":100,\\n\"\n+                                + \"        \\\"company\\\":{\\n\"\n+                                + \"           \\\"symbol\\\":\\\"WSO2\\\"\\n\"\n+                                + \"       },\\n\"\n+                                + \"        \\\"price\\\":55.6\\n\"\n+                                + \"    }\\n\"\n+                                + \"}\")\n+        }\n+)\n+\n+public class JsonSourceMapper extends SourceMapper {\n+\n+    private static final String DEFAULT_JSON_MAPPING_PREFIX = \"$.\";\n+    private static final String DEFAULT_JSON_EVENT_IDENTIFIER = \"event\";\n+    private static final String DEFAULT_ENCLOSING_ELEMENT = \"$\";\n+    private static final String FAIL_ON_MISSING_ATTRIBUTE_IDENTIFIER = \"fail.on.missing.attribute\";\n+    private static final String ENCLOSING_ELEMENT_IDENTIFIER = \"enclosing.element\";\n+    private static final Logger log = Logger.getLogger(JsonSourceMapper.class);\n+\n+    private StreamDefinition streamDefinition;\n+    private MappingPositionData[] mappingPositions;\n+    private List<Attribute> streamAttributes;\n+    private boolean isCustomMappingEnabled = false;\n+    private boolean failOnMissingAttribute = true;\n+    private String enclosingElement = null;\n+    private AttributeConverter attributeConverter = new AttributeConverter();\n+    private JsonFactory factory;\n+    private int attributesSize;\n+\n+    @Override\n+    public void init(StreamDefinition streamDefinition, OptionHolder optionHolder,\n+                     List<AttributeMapping> attributeMappingList, ConfigReader configReader) {\n+        this.streamDefinition = streamDefinition;\n+        this.streamAttributes = this.streamDefinition.getAttributeList();\n+        attributesSize = this.streamDefinition.getAttributeList().size();","path":"modules/siddhi-extensions/input-mappers/json-input-mapper/src/main/java/org/wso2/siddhi/extension/input/mapper/json/JsonSourceMapper.java","position":144,"original_position":144,"commit_id":"7b32a8925b1304973fc96677b822729457d434ac","original_commit_id":"7b32a8925b1304973fc96677b822729457d434ac","user":{"login":"minudika","id":6940029,"node_id":"MDQ6VXNlcjY5NDAwMjk=","avatar_url":"https://avatars0.githubusercontent.com/u/6940029?v=4","gravatar_id":"","url":"https://api.github.com/users/minudika","html_url":"https://github.com/minudika","followers_url":"https://api.github.com/users/minudika/followers","following_url":"https://api.github.com/users/minudika/following{/other_user}","gists_url":"https://api.github.com/users/minudika/gists{/gist_id}","starred_url":"https://api.github.com/users/minudika/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minudika/subscriptions","organizations_url":"https://api.github.com/users/minudika/orgs","repos_url":"https://api.github.com/users/minudika/repos","events_url":"https://api.github.com/users/minudika/events{/privacy}","received_events_url":"https://api.github.com/users/minudika/received_events","type":"User","site_admin":false},"body":"Fixed with PR https://github.com/wso2-extensions/siddhi-map-json/pull/56","created_at":"2018-09-10T07:01:45Z","updated_at":"2018-09-10T07:01:45Z","html_url":"https://github.com/wso2/siddhi/pull/358#discussion_r216215573","pull_request_url":"https://api.github.com/repos/wso2/siddhi/pulls/358","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/comments/216215573"},"html":{"href":"https://github.com/wso2/siddhi/pull/358#discussion_r216215573"},"pull_request":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/358"}},"in_reply_to_id":211927523},"pull_request":{"url":"https://api.github.com/repos/wso2/siddhi/pulls/358","id":120737159,"node_id":"MDExOlB1bGxSZXF1ZXN0MTIwNzM3MTU5","html_url":"https://github.com/wso2/siddhi/pull/358","diff_url":"https://github.com/wso2/siddhi/pull/358.diff","patch_url":"https://github.com/wso2/siddhi/pull/358.patch","issue_url":"https://api.github.com/repos/wso2/siddhi/issues/358","number":358,"state":"closed","locked":false,"title":"Json mapper extension","user":{"login":"minudika","id":6940029,"node_id":"MDQ6VXNlcjY5NDAwMjk=","avatar_url":"https://avatars0.githubusercontent.com/u/6940029?v=4","gravatar_id":"","url":"https://api.github.com/users/minudika","html_url":"https://github.com/minudika","followers_url":"https://api.github.com/users/minudika/followers","following_url":"https://api.github.com/users/minudika/following{/other_user}","gists_url":"https://api.github.com/users/minudika/gists{/gist_id}","starred_url":"https://api.github.com/users/minudika/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minudika/subscriptions","organizations_url":"https://api.github.com/users/minudika/orgs","repos_url":"https://api.github.com/users/minudika/repos","events_url":"https://api.github.com/users/minudika/events{/privacy}","received_events_url":"https://api.github.com/users/minudika/received_events","type":"User","site_admin":false},"body":"Please review and merge.","created_at":"2017-05-16T03:21:26Z","updated_at":"2018-09-10T07:01:45Z","closed_at":"2017-05-16T11:22:06Z","merged_at":"2017-05-16T11:22:06Z","merge_commit_sha":"eea67cd5fcf95c0e76bb3fe8478dddde37f8e4cd","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/wso2/siddhi/pulls/358/commits","review_comments_url":"https://api.github.com/repos/wso2/siddhi/pulls/358/comments","review_comment_url":"https://api.github.com/repos/wso2/siddhi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wso2/siddhi/issues/358/comments","statuses_url":"https://api.github.com/repos/wso2/siddhi/statuses/7b32a8925b1304973fc96677b822729457d434ac","head":{"label":"minudika:json-mapper-extension","ref":"json-mapper-extension","sha":"7b32a8925b1304973fc96677b822729457d434ac","user":{"login":"minudika","id":6940029,"node_id":"MDQ6VXNlcjY5NDAwMjk=","avatar_url":"https://avatars0.githubusercontent.com/u/6940029?v=4","gravatar_id":"","url":"https://api.github.com/users/minudika","html_url":"https://github.com/minudika","followers_url":"https://api.github.com/users/minudika/followers","following_url":"https://api.github.com/users/minudika/following{/other_user}","gists_url":"https://api.github.com/users/minudika/gists{/gist_id}","starred_url":"https://api.github.com/users/minudika/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minudika/subscriptions","organizations_url":"https://api.github.com/users/minudika/orgs","repos_url":"https://api.github.com/users/minudika/repos","events_url":"https://api.github.com/users/minudika/events{/privacy}","received_events_url":"https://api.github.com/users/minudika/received_events","type":"User","site_admin":false},"repo":null},"base":{"label":"wso2:master","ref":"master","sha":"833c579cc2fdab23bdfdde3d160419324d855b03","user":{"login":"wso2","id":533043,"node_id":"MDEyOk9yZ2FuaXphdGlvbjUzMzA0Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/533043?v=4","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"repo":{"id":18988631,"node_id":"MDEwOlJlcG9zaXRvcnkxODk4ODYzMQ==","name":"siddhi","full_name":"wso2/siddhi","owner":{"login":"wso2","id":533043,"node_id":"MDEyOk9yZ2FuaXphdGlvbjUzMzA0Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/533043?v=4","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2/siddhi","description":"Stream Processing and Complex Event Processing Engine","fork":false,"url":"https://api.github.com/repos/wso2/siddhi","forks_url":"https://api.github.com/repos/wso2/siddhi/forks","keys_url":"https://api.github.com/repos/wso2/siddhi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2/siddhi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2/siddhi/teams","hooks_url":"https://api.github.com/repos/wso2/siddhi/hooks","issue_events_url":"https://api.github.com/repos/wso2/siddhi/issues/events{/number}","events_url":"https://api.github.com/repos/wso2/siddhi/events","assignees_url":"https://api.github.com/repos/wso2/siddhi/assignees{/user}","branches_url":"https://api.github.com/repos/wso2/siddhi/branches{/branch}","tags_url":"https://api.github.com/repos/wso2/siddhi/tags","blobs_url":"https://api.github.com/repos/wso2/siddhi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2/siddhi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2/siddhi/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2/siddhi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2/siddhi/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2/siddhi/languages","stargazers_url":"https://api.github.com/repos/wso2/siddhi/stargazers","contributors_url":"https://api.github.com/repos/wso2/siddhi/contributors","subscribers_url":"https://api.github.com/repos/wso2/siddhi/subscribers","subscription_url":"https://api.github.com/repos/wso2/siddhi/subscription","commits_url":"https://api.github.com/repos/wso2/siddhi/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2/siddhi/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2/siddhi/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2/siddhi/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2/siddhi/contents/{+path}","compare_url":"https://api.github.com/repos/wso2/siddhi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2/siddhi/merges","archive_url":"https://api.github.com/repos/wso2/siddhi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2/siddhi/downloads","issues_url":"https://api.github.com/repos/wso2/siddhi/issues{/number}","pulls_url":"https://api.github.com/repos/wso2/siddhi/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2/siddhi/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2/siddhi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2/siddhi/labels{/name}","releases_url":"https://api.github.com/repos/wso2/siddhi/releases{/id}","deployments_url":"https://api.github.com/repos/wso2/siddhi/deployments","created_at":"2014-04-21T09:51:36Z","updated_at":"2018-09-07T07:40:17Z","pushed_at":"2018-09-07T07:40:21Z","git_url":"git://github.com/wso2/siddhi.git","ssh_url":"git@github.com:wso2/siddhi.git","clone_url":"https://github.com/wso2/siddhi.git","svn_url":"https://github.com/wso2/siddhi","homepage":"https://wso2.github.io/siddhi/","size":31790,"stargazers_count":515,"watchers_count":515,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":301,"mirror_url":null,"archived":false,"open_issues_count":46,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":301,"open_issues":46,"watchers":515,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/358"},"html":{"href":"https://github.com/wso2/siddhi/pull/358"},"issue":{"href":"https://api.github.com/repos/wso2/siddhi/issues/358"},"comments":{"href":"https://api.github.com/repos/wso2/siddhi/issues/358/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/358/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wso2/siddhi/pulls/358/commits"},"statuses":{"href":"https://api.github.com/repos/wso2/siddhi/statuses/7b32a8925b1304973fc96677b822729457d434ac"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"minudika"}}