{"action":"created","issue":{"url":"https://api.github.com/repos/eclipse/vert.x/issues/1637","repository_url":"https://api.github.com/repos/eclipse/vert.x","labels_url":"https://api.github.com/repos/eclipse/vert.x/issues/1637/labels{/name}","comments_url":"https://api.github.com/repos/eclipse/vert.x/issues/1637/comments","events_url":"https://api.github.com/repos/eclipse/vert.x/issues/1637/events","html_url":"https://github.com/eclipse/vert.x/issues/1637","id":178566376,"number":1637,"title":"JsonObject#getMap() differs for json from string or built by chaining multiple JsonObjects","user":{"login":"marcinczeczko","id":4218395,"avatar_url":"https://avatars.githubusercontent.com/u/4218395?v=3","gravatar_id":"","url":"https://api.github.com/users/marcinczeczko","html_url":"https://github.com/marcinczeczko","followers_url":"https://api.github.com/users/marcinczeczko/followers","following_url":"https://api.github.com/users/marcinczeczko/following{/other_user}","gists_url":"https://api.github.com/users/marcinczeczko/gists{/gist_id}","starred_url":"https://api.github.com/users/marcinczeczko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcinczeczko/subscriptions","organizations_url":"https://api.github.com/users/marcinczeczko/orgs","repos_url":"https://api.github.com/users/marcinczeczko/repos","events_url":"https://api.github.com/users/marcinczeczko/events{/privacy}","received_events_url":"https://api.github.com/users/marcinczeczko/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-09-22T09:52:10Z","updated_at":"2016-09-24T08:11:32Z","closed_at":"2016-09-24T08:11:26Z","body":"I found some inconsistency in the underneath map of JsonObject. It looks to me as some inconsistency in how JsonObject builds underlying map. \r\n\r\nConsider following scenario.\r\n1. Given I have Json as string received from some source, e.g.:\r\n```json\r\n{\r\n   \"data\": \"foo\",\r\n   \"my\": {\r\n      \"data\": \"foo\"\r\n   }\r\n}\r\n```\r\n2. I can build JsonObject and then get it as map. \"my\" object is represented as below in the map\r\n```\r\ndata=class java.lang.String\r\nmy=class java.util.LinkedHashMap\r\n```\r\n3. However, if I add another object to that json programatically, such as: json.put(\"other\", new JsonObject().put(\"some\",\"data\")); and then will get it again as map, then \"other\" is not represented as Map\r\n```\r\ndata=class java.lang.String\r\nmy=class java.util.LinkedHashMap\r\nother=class io.vertx.core.json.JsonObject\r\n```\r\nIf I'd use JsonObject methods to access any element in my json it would be fine. However, I'm doing this processing as explained above and finally convert it to Map as other elements of the system requires Map. However, current behavior is cumbersome, and when working with JsonObject by adding some new nested object I need literally use Maps to get consistency, I'd prefer to use JsonObject methods as they are fluent and more readable.\r\n\r\nBelow is very simple piece of code that you can see what I mean:\r\n```java\r\n    String jsonRaw = \"{\\\"data\\\": \\\"foo\\\",\\\"my\\\": {\\\"data\\\": \\\"foo\\\"}}\";\r\n\r\n    JsonObject json = new JsonObject(jsonRaw);\r\n\r\n    json.getMap().entrySet().stream()\r\n            .forEach(entry -> System.out.println(entry.getKey()+\"=\"+entry.getValue().getClass()));\r\n\r\n    //I can go through Map and access my objects using map interface\r\n    Map<String, Object> my = (Map<String, Object>)json.getMap().get(\"my\");\r\n    System.out.println(my.get(\"data\"));\r\n\r\n    System.out.println(\"--- Adding new object---\");\r\n    json.put(\"other\", new JsonObject().put(\"some\", \"data\"));\r\n\r\n    json.getMap().entrySet().stream()\r\n            .forEach(entry -> System.out.println(entry.getKey()+\"=\"+entry.getValue().getClass()));\r\n\r\n    //In this case I need to get JsonObject from map, then get Map in order to access data. \r\n    // it breaks the whole idea that JsonObject can be represented by Map.\r\n    JsonObject other = (JsonObject)json.getMap().get(\"other\");\r\n    System.out.println(other.getMap().get(\"some\"));\r\n```"},"comment":{"url":"https://api.github.com/repos/eclipse/vert.x/issues/comments/249352215","html_url":"https://github.com/eclipse/vert.x/issues/1637#issuecomment-249352215","issue_url":"https://api.github.com/repos/eclipse/vert.x/issues/1637","id":249352215,"user":{"login":"vietj","id":225674,"avatar_url":"https://avatars.githubusercontent.com/u/225674?v=3","gravatar_id":"","url":"https://api.github.com/users/vietj","html_url":"https://github.com/vietj","followers_url":"https://api.github.com/users/vietj/followers","following_url":"https://api.github.com/users/vietj/following{/other_user}","gists_url":"https://api.github.com/users/vietj/gists{/gist_id}","starred_url":"https://api.github.com/users/vietj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vietj/subscriptions","organizations_url":"https://api.github.com/users/vietj/orgs","repos_url":"https://api.github.com/users/vietj/repos","events_url":"https://api.github.com/users/vietj/events{/privacy}","received_events_url":"https://api.github.com/users/vietj/received_events","type":"User","site_admin":false},"created_at":"2016-09-24T08:11:32Z","updated_at":"2016-09-24T08:11:32Z","body":"added in the javadoc"}}
{"actor":{"display_login":"vietj"}}