{"action":"created","comment":{"url":"https://api.github.com/repos/Talend/daikon/pulls/comments/126950574","pull_request_review_id":49471214,"id":126950574,"diff_hunk":"@@ -0,0 +1,196 @@\n+package org.talend.daikon.avro.converter;\n+\n+import java.util.Iterator;\n+import java.util.Map;\n+import java.util.UUID;\n+\n+import org.apache.avro.Schema;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import com.fasterxml.jackson.databind.JsonNode;\n+import com.fasterxml.jackson.databind.ObjectMapper;\n+import com.fasterxml.jackson.databind.node.ArrayNode;\n+import com.fasterxml.jackson.databind.node.JsonNodeType;\n+import com.fasterxml.jackson.databind.node.NullNode;\n+import com.fasterxml.jackson.databind.node.ObjectNode;\n+\n+public class ConvertJson implements AvroConverter<String, Schema> {\n+\n+    private static final Logger logger = LoggerFactory.getLogger(AvroConverter.class);\n+\n+    private final ObjectMapper mapper;\n+\n+    /**\n+     * Constructor\n+     *\n+     * @param mapper\n+     */\n+    public ConvertJson(final ObjectMapper mapper) {\n+        this.mapper = mapper;\n+    }\n+\n+    @Override\n+    public Schema getSchema() {\n+        return null;\n+    }\n+\n+    @Override\n+    public Class<String> getDatumClass() {\n+        return null;\n+    }\n+\n+    @Override\n+    public String convertToDatum(Schema value) {\n+        return null;\n+    }\n+\n+    /**\n+     * Convert json string to avro schema.\n+     *\n+     * Example:\n+     *\n+     * json string parameter: {\"a\": {\"b\": \"b1\"}, \"d\": 100}\n+     *\n+     * avro schema constructed:\n+     * {\"type\":\"record\",\"name\":\"outer_record\",\"namespace\":\"org.talend\",\n+     * \"fields\":[{\"name\":\"a\",\"type\":{\"type\":\"record\",\"name\":\"a_98\",\"fields\":[{\"name\":\"b\",\"type\":[\"null\",\"string\"]}]}},\n+     * {\"name\":\"d\",\"type\":[\"null\",\"int\"]}]}\n+     *\n+     * @param json string to convert\n+     * @return avro schema constructed\n+     */\n+    @Override\n+    public Schema convertToAvro(String json) {\n+        Schema outputSchema = null;\n+        try {\n+            final JsonNode jsonNode = mapper.readTree(json);\n+            final ObjectNode finalSchema = mapper.createObjectNode();\n+            finalSchema.put(\"namespace\", \"org.talend\");\n+            finalSchema.put(ConvertJsonConstant.NAME, \"outer_record\");\n+            finalSchema.put(ConvertJsonConstant.TYPE, ConvertJsonConstant.RECORD);\n+            finalSchema.set(ConvertJsonConstant.FIELDS, getFields(jsonNode));\n+            outputSchema = new Schema.Parser().parse(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(finalSchema));\n+        } catch (Exception ex) {\n+            logger.error(ex.getMessage());\n+        }\n+        return outputSchema;\n+    }\n+\n+    /**\n+     * Construct the fields schema from json node. Supported data types are: INT, LONG, DOUBLE, STRING, ARRAY, OBJECT.\n+     *\n+     * Example:\n+     *\n+     * jsonNode parameter: {\"a\": {\"b\": \"b1\"}, \"d\": 100}\n+     *\n+     * jsonNode fields schema:\n+     * [{\"name\":\"a\",\"type\":{\"type\":\"record\",\"name\":\"a_49\",\"fields\":[{\"name\":\"b\",\"type\":[\"null\",\"string\"]}]}},{\"name\":\"d\",\"type\":[\"null\",\"int\"]}]\n+     *\n+     * @param jsonNode\n+     * @return fields schema of json node\n+     */\n+    public ArrayNode getFields(final JsonNode jsonNode) {","path":"daikon/src/main/java/org/talend/daikon/avro/converter/ConvertJson.java","position":93,"original_position":93,"commit_id":"fcae5052731e11b834edfc0122f3a2f678971bff","original_commit_id":"fcae5052731e11b834edfc0122f3a2f678971bff","user":{"login":"gonchar-ivan","id":7621737,"avatar_url":"https://avatars0.githubusercontent.com/u/7621737?v=3","gravatar_id":"","url":"https://api.github.com/users/gonchar-ivan","html_url":"https://github.com/gonchar-ivan","followers_url":"https://api.github.com/users/gonchar-ivan/followers","following_url":"https://api.github.com/users/gonchar-ivan/following{/other_user}","gists_url":"https://api.github.com/users/gonchar-ivan/gists{/gist_id}","starred_url":"https://api.github.com/users/gonchar-ivan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonchar-ivan/subscriptions","organizations_url":"https://api.github.com/users/gonchar-ivan/orgs","repos_url":"https://api.github.com/users/gonchar-ivan/repos","events_url":"https://api.github.com/users/gonchar-ivan/events{/privacy}","received_events_url":"https://api.github.com/users/gonchar-ivan/received_events","type":"User","site_admin":false},"body":"I suggest to make this method package visible.","created_at":"2017-07-12T13:16:38Z","updated_at":"2017-07-12T13:29:22Z","html_url":"https://github.com/Talend/daikon/pull/252#discussion_r126950574","pull_request_url":"https://api.github.com/repos/Talend/daikon/pulls/252","_links":{"self":{"href":"https://api.github.com/repos/Talend/daikon/pulls/comments/126950574"},"html":{"href":"https://github.com/Talend/daikon/pull/252#discussion_r126950574"},"pull_request":{"href":"https://api.github.com/repos/Talend/daikon/pulls/252"}}},"pull_request":{"url":"https://api.github.com/repos/Talend/daikon/pulls/252","id":129913056,"html_url":"https://github.com/Talend/daikon/pull/252","diff_url":"https://github.com/Talend/daikon/pull/252.diff","patch_url":"https://github.com/Talend/daikon/pull/252.patch","issue_url":"https://api.github.com/repos/Talend/daikon/issues/252","number":252,"state":"open","locked":false,"title":"feat(TFD-1713): Create converter json to avro schema","user":{"login":"zafkirTalend","id":26114895,"avatar_url":"https://avatars3.githubusercontent.com/u/26114895?v=3","gravatar_id":"","url":"https://api.github.com/users/zafkirTalend","html_url":"https://github.com/zafkirTalend","followers_url":"https://api.github.com/users/zafkirTalend/followers","following_url":"https://api.github.com/users/zafkirTalend/following{/other_user}","gists_url":"https://api.github.com/users/zafkirTalend/gists{/gist_id}","starred_url":"https://api.github.com/users/zafkirTalend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zafkirTalend/subscriptions","organizations_url":"https://api.github.com/users/zafkirTalend/orgs","repos_url":"https://api.github.com/users/zafkirTalend/repos","events_url":"https://api.github.com/users/zafkirTalend/events{/privacy}","received_events_url":"https://api.github.com/users/zafkirTalend/received_events","type":"User","site_admin":false},"body":"**Please check if the PR fulfills these requirements**\r\n\r\n- [ ] The commit(s) message(s) follows our [guidelines](https://github.com/talend/tools/blob/master/tools-root-github/CONTRIBUTING.md#commit-message-format) ?\r\n- [ ] Tests for the changes have been added (for bug fixes / features) ?\r\n- [ ] Docs have been added / updated (for bug fixes / features) ?\r\n- [ ] The code coverage on new code >75%\r\n- [ ] The new code does not introduce new technical issues (sonar / eslint)\r\n\r\n\r\n**What kind of change does this PR introduce?**\r\n\r\n- [ ] Bugfix\r\n- [x] Feature\r\n- [ ] Code style update (formatting, local variables)\r\n- [ ] Refactoring (no functional changes, no api changes)\r\n- [ ] Build / CI related changes\r\n- [ ] Other... Please describe:\r\n\r\n**What is the current behavior?** (You can also link to an open issue here)\r\n\r\nNo converter json to avro schema.\r\n\r\n**What is the new behavior?**\r\n\r\nNew converter json to avro schema.\r\n\r\n**Does this PR introduce a breaking change?**\r\n\r\n- [ ] Yes\r\n- [x] No\r\n\r\n**Other information**:\r\n","created_at":"2017-07-11T13:51:19Z","updated_at":"2017-07-12T13:29:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b32eef4508c2fd0f9e93e9be986aacfdaa43d393","assignee":{"login":"zafkirTalend","id":26114895,"avatar_url":"https://avatars3.githubusercontent.com/u/26114895?v=3","gravatar_id":"","url":"https://api.github.com/users/zafkirTalend","html_url":"https://github.com/zafkirTalend","followers_url":"https://api.github.com/users/zafkirTalend/followers","following_url":"https://api.github.com/users/zafkirTalend/following{/other_user}","gists_url":"https://api.github.com/users/zafkirTalend/gists{/gist_id}","starred_url":"https://api.github.com/users/zafkirTalend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zafkirTalend/subscriptions","organizations_url":"https://api.github.com/users/zafkirTalend/orgs","repos_url":"https://api.github.com/users/zafkirTalend/repos","events_url":"https://api.github.com/users/zafkirTalend/events{/privacy}","received_events_url":"https://api.github.com/users/zafkirTalend/received_events","type":"User","site_admin":false},"assignees":[{"login":"zafkirTalend","id":26114895,"avatar_url":"https://avatars3.githubusercontent.com/u/26114895?v=3","gravatar_id":"","url":"https://api.github.com/users/zafkirTalend","html_url":"https://github.com/zafkirTalend","followers_url":"https://api.github.com/users/zafkirTalend/followers","following_url":"https://api.github.com/users/zafkirTalend/following{/other_user}","gists_url":"https://api.github.com/users/zafkirTalend/gists{/gist_id}","starred_url":"https://api.github.com/users/zafkirTalend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zafkirTalend/subscriptions","organizations_url":"https://api.github.com/users/zafkirTalend/orgs","repos_url":"https://api.github.com/users/zafkirTalend/repos","events_url":"https://api.github.com/users/zafkirTalend/events{/privacy}","received_events_url":"https://api.github.com/users/zafkirTalend/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/Talend/daikon/pulls/252/commits","review_comments_url":"https://api.github.com/repos/Talend/daikon/pulls/252/comments","review_comment_url":"https://api.github.com/repos/Talend/daikon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Talend/daikon/issues/252/comments","statuses_url":"https://api.github.com/repos/Talend/daikon/statuses/fcae5052731e11b834edfc0122f3a2f678971bff","head":{"label":"Talend:feat/TFD-1713","ref":"feat/TFD-1713","sha":"fcae5052731e11b834edfc0122f3a2f678971bff","user":{"login":"Talend","id":459687,"avatar_url":"https://avatars1.githubusercontent.com/u/459687?v=3","gravatar_id":"","url":"https://api.github.com/users/Talend","html_url":"https://github.com/Talend","followers_url":"https://api.github.com/users/Talend/followers","following_url":"https://api.github.com/users/Talend/following{/other_user}","gists_url":"https://api.github.com/users/Talend/gists{/gist_id}","starred_url":"https://api.github.com/users/Talend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Talend/subscriptions","organizations_url":"https://api.github.com/users/Talend/orgs","repos_url":"https://api.github.com/users/Talend/repos","events_url":"https://api.github.com/users/Talend/events{/privacy}","received_events_url":"https://api.github.com/users/Talend/received_events","type":"Organization","site_admin":false},"repo":{"id":42255499,"name":"daikon","full_name":"Talend/daikon","owner":{"login":"Talend","id":459687,"avatar_url":"https://avatars1.githubusercontent.com/u/459687?v=3","gravatar_id":"","url":"https://api.github.com/users/Talend","html_url":"https://github.com/Talend","followers_url":"https://api.github.com/users/Talend/followers","following_url":"https://api.github.com/users/Talend/following{/other_user}","gists_url":"https://api.github.com/users/Talend/gists{/gist_id}","starred_url":"https://api.github.com/users/Talend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Talend/subscriptions","organizations_url":"https://api.github.com/users/Talend/orgs","repos_url":"https://api.github.com/users/Talend/repos","events_url":"https://api.github.com/users/Talend/events{/privacy}","received_events_url":"https://api.github.com/users/Talend/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Talend/daikon","description":"Commons back-end java classes shared by dataprep and components services (for now)","fork":false,"url":"https://api.github.com/repos/Talend/daikon","forks_url":"https://api.github.com/repos/Talend/daikon/forks","keys_url":"https://api.github.com/repos/Talend/daikon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Talend/daikon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Talend/daikon/teams","hooks_url":"https://api.github.com/repos/Talend/daikon/hooks","issue_events_url":"https://api.github.com/repos/Talend/daikon/issues/events{/number}","events_url":"https://api.github.com/repos/Talend/daikon/events","assignees_url":"https://api.github.com/repos/Talend/daikon/assignees{/user}","branches_url":"https://api.github.com/repos/Talend/daikon/branches{/branch}","tags_url":"https://api.github.com/repos/Talend/daikon/tags","blobs_url":"https://api.github.com/repos/Talend/daikon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Talend/daikon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Talend/daikon/git/refs{/sha}","trees_url":"https://api.github.com/repos/Talend/daikon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Talend/daikon/statuses/{sha}","languages_url":"https://api.github.com/repos/Talend/daikon/languages","stargazers_url":"https://api.github.com/repos/Talend/daikon/stargazers","contributors_url":"https://api.github.com/repos/Talend/daikon/contributors","subscribers_url":"https://api.github.com/repos/Talend/daikon/subscribers","subscription_url":"https://api.github.com/repos/Talend/daikon/subscription","commits_url":"https://api.github.com/repos/Talend/daikon/commits{/sha}","git_commits_url":"https://api.github.com/repos/Talend/daikon/git/commits{/sha}","comments_url":"https://api.github.com/repos/Talend/daikon/comments{/number}","issue_comment_url":"https://api.github.com/repos/Talend/daikon/issues/comments{/number}","contents_url":"https://api.github.com/repos/Talend/daikon/contents/{+path}","compare_url":"https://api.github.com/repos/Talend/daikon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Talend/daikon/merges","archive_url":"https://api.github.com/repos/Talend/daikon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Talend/daikon/downloads","issues_url":"https://api.github.com/repos/Talend/daikon/issues{/number}","pulls_url":"https://api.github.com/repos/Talend/daikon/pulls{/number}","milestones_url":"https://api.github.com/repos/Talend/daikon/milestones{/number}","notifications_url":"https://api.github.com/repos/Talend/daikon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Talend/daikon/labels{/name}","releases_url":"https://api.github.com/repos/Talend/daikon/releases{/id}","deployments_url":"https://api.github.com/repos/Talend/daikon/deployments","created_at":"2015-09-10T16:08:46Z","updated_at":"2017-03-29T20:30:05Z","pushed_at":"2017-07-12T12:47:11Z","git_url":"git://github.com/Talend/daikon.git","ssh_url":"git@github.com:Talend/daikon.git","clone_url":"https://github.com/Talend/daikon.git","svn_url":"https://github.com/Talend/daikon","homepage":null,"size":3574,"stargazers_count":3,"watchers_count":3,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":6,"forks":16,"open_issues":6,"watchers":3,"default_branch":"master"}},"base":{"label":"Talend:master","ref":"master","sha":"0721be6287774030af39e0217854f700a8f54485","user":{"login":"Talend","id":459687,"avatar_url":"https://avatars1.githubusercontent.com/u/459687?v=3","gravatar_id":"","url":"https://api.github.com/users/Talend","html_url":"https://github.com/Talend","followers_url":"https://api.github.com/users/Talend/followers","following_url":"https://api.github.com/users/Talend/following{/other_user}","gists_url":"https://api.github.com/users/Talend/gists{/gist_id}","starred_url":"https://api.github.com/users/Talend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Talend/subscriptions","organizations_url":"https://api.github.com/users/Talend/orgs","repos_url":"https://api.github.com/users/Talend/repos","events_url":"https://api.github.com/users/Talend/events{/privacy}","received_events_url":"https://api.github.com/users/Talend/received_events","type":"Organization","site_admin":false},"repo":{"id":42255499,"name":"daikon","full_name":"Talend/daikon","owner":{"login":"Talend","id":459687,"avatar_url":"https://avatars1.githubusercontent.com/u/459687?v=3","gravatar_id":"","url":"https://api.github.com/users/Talend","html_url":"https://github.com/Talend","followers_url":"https://api.github.com/users/Talend/followers","following_url":"https://api.github.com/users/Talend/following{/other_user}","gists_url":"https://api.github.com/users/Talend/gists{/gist_id}","starred_url":"https://api.github.com/users/Talend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Talend/subscriptions","organizations_url":"https://api.github.com/users/Talend/orgs","repos_url":"https://api.github.com/users/Talend/repos","events_url":"https://api.github.com/users/Talend/events{/privacy}","received_events_url":"https://api.github.com/users/Talend/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Talend/daikon","description":"Commons back-end java classes shared by dataprep and components services (for now)","fork":false,"url":"https://api.github.com/repos/Talend/daikon","forks_url":"https://api.github.com/repos/Talend/daikon/forks","keys_url":"https://api.github.com/repos/Talend/daikon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Talend/daikon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Talend/daikon/teams","hooks_url":"https://api.github.com/repos/Talend/daikon/hooks","issue_events_url":"https://api.github.com/repos/Talend/daikon/issues/events{/number}","events_url":"https://api.github.com/repos/Talend/daikon/events","assignees_url":"https://api.github.com/repos/Talend/daikon/assignees{/user}","branches_url":"https://api.github.com/repos/Talend/daikon/branches{/branch}","tags_url":"https://api.github.com/repos/Talend/daikon/tags","blobs_url":"https://api.github.com/repos/Talend/daikon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Talend/daikon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Talend/daikon/git/refs{/sha}","trees_url":"https://api.github.com/repos/Talend/daikon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Talend/daikon/statuses/{sha}","languages_url":"https://api.github.com/repos/Talend/daikon/languages","stargazers_url":"https://api.github.com/repos/Talend/daikon/stargazers","contributors_url":"https://api.github.com/repos/Talend/daikon/contributors","subscribers_url":"https://api.github.com/repos/Talend/daikon/subscribers","subscription_url":"https://api.github.com/repos/Talend/daikon/subscription","commits_url":"https://api.github.com/repos/Talend/daikon/commits{/sha}","git_commits_url":"https://api.github.com/repos/Talend/daikon/git/commits{/sha}","comments_url":"https://api.github.com/repos/Talend/daikon/comments{/number}","issue_comment_url":"https://api.github.com/repos/Talend/daikon/issues/comments{/number}","contents_url":"https://api.github.com/repos/Talend/daikon/contents/{+path}","compare_url":"https://api.github.com/repos/Talend/daikon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Talend/daikon/merges","archive_url":"https://api.github.com/repos/Talend/daikon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Talend/daikon/downloads","issues_url":"https://api.github.com/repos/Talend/daikon/issues{/number}","pulls_url":"https://api.github.com/repos/Talend/daikon/pulls{/number}","milestones_url":"https://api.github.com/repos/Talend/daikon/milestones{/number}","notifications_url":"https://api.github.com/repos/Talend/daikon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Talend/daikon/labels{/name}","releases_url":"https://api.github.com/repos/Talend/daikon/releases{/id}","deployments_url":"https://api.github.com/repos/Talend/daikon/deployments","created_at":"2015-09-10T16:08:46Z","updated_at":"2017-03-29T20:30:05Z","pushed_at":"2017-07-12T12:47:11Z","git_url":"git://github.com/Talend/daikon.git","ssh_url":"git@github.com:Talend/daikon.git","clone_url":"https://github.com/Talend/daikon.git","svn_url":"https://github.com/Talend/daikon","homepage":null,"size":3574,"stargazers_count":3,"watchers_count":3,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":6,"forks":16,"open_issues":6,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Talend/daikon/pulls/252"},"html":{"href":"https://github.com/Talend/daikon/pull/252"},"issue":{"href":"https://api.github.com/repos/Talend/daikon/issues/252"},"comments":{"href":"https://api.github.com/repos/Talend/daikon/issues/252/comments"},"review_comments":{"href":"https://api.github.com/repos/Talend/daikon/pulls/252/comments"},"review_comment":{"href":"https://api.github.com/repos/Talend/daikon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Talend/daikon/pulls/252/commits"},"statuses":{"href":"https://api.github.com/repos/Talend/daikon/statuses/fcae5052731e11b834edfc0122f3a2f678971bff"}}}}
{"actor":{"display_login":"gonchar-ivan"}}