{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/6169","repository_url":"https://api.github.com/repos/realm/realm-java","labels_url":"https://api.github.com/repos/realm/realm-java/issues/6169/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/6169/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/6169/events","html_url":"https://github.com/realm/realm-java/issues/6169","id":361540977,"node_id":"MDU6SXNzdWUzNjE1NDA5Nzc=","number":6169,"title":"Kotlin use GSON Serialize endless loop","user":{"login":"Kandom","id":16002666,"node_id":"MDQ6VXNlcjE2MDAyNjY2","avatar_url":"https://avatars2.githubusercontent.com/u/16002666?v=4","gravatar_id":"","url":"https://api.github.com/users/Kandom","html_url":"https://github.com/Kandom","followers_url":"https://api.github.com/users/Kandom/followers","following_url":"https://api.github.com/users/Kandom/following{/other_user}","gists_url":"https://api.github.com/users/Kandom/gists{/gist_id}","starred_url":"https://api.github.com/users/Kandom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kandom/subscriptions","organizations_url":"https://api.github.com/users/Kandom/orgs","repos_url":"https://api.github.com/users/Kandom/repos","events_url":"https://api.github.com/users/Kandom/events{/privacy}","received_events_url":"https://api.github.com/users/Kandom/received_events","type":"User","site_admin":false},"labels":[{"id":662397242,"node_id":"MDU6TGFiZWw2NjIzOTcyNDI=","url":"https://api.github.com/repos/realm/realm-java/labels/O:User","name":"O:User","color":"006b75","default":false},{"id":3545600,"node_id":"MDU6TGFiZWwzNTQ1NjAw","url":"https://api.github.com/repos/realm/realm-java/labels/T:Help","name":"T:Help","color":"cc317c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-09-19T01:19:46Z","updated_at":"2018-09-21T09:00:46Z","closed_at":null,"author_association":"NONE","body":"Code:\r\n```\r\nopen class Person : RealmObject() {\r\n    var age: Int = 0\r\n    var name: String = \"\"\r\n}\r\n\r\n\r\nclass PersonSerializer : JsonSerializer<Person> {\r\n    override fun serialize(src: Person, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {\r\n        val jsonObject = JsonObject()\r\n        jsonObject.addProperty(\"name\", src.name)\r\n        jsonObject.addProperty(\"age\", src.age)\r\n        return jsonObject\r\n    }\r\n}\r\n\r\n\r\n        val realm = Realm.getDefaultInstance()\r\n        val person = realm.where(Person::class.java).findFirst()\r\n        val gson = GsonBuilder()\r\n                .setExclusionStrategies(object : ExclusionStrategy {\r\n                    override fun shouldSkipField(f: FieldAttributes): Boolean {\r\n                        return f.declaringClass == RealmObject::class.java\r\n                    }\r\n\r\n                    override fun shouldSkipClass(clazz: Class<*>): Boolean {\r\n                        return false\r\n                    }\r\n                })\r\n                .registerTypeAdapter(Person::class.java, PersonSerializer())\r\n                .create()\r\n\r\n        val personJSON = gson.toJson(person)\r\n        Log.d(\"MainActivity\", \"$personJSON\")\r\n        realm.close()\r\n```\r\nIt cause an endless loop. But if I change to\r\nval personJSON = gson.toJson(realm.copyFromRealm(person))\r\n\r\nThe entity serialized fine. I just translate the realm GSON demo from java to Kotlin with the official document https://gist.github.com/cmelchior/ddac8efd018123a1e53a\r\n\r\nSome body can help?\r\n\r\n#### Version of Realm and tooling\r\nRealm version(s): 5.4.1\r\n\r\nRealm sync feature enabled: NO\r\n\r\nAndroid Studio version: 3.4.1\r\n\r\nWhich Android version and device: compileSdkVersion 27\r\n"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/423465234","html_url":"https://github.com/realm/realm-java/issues/6169#issuecomment-423465234","issue_url":"https://api.github.com/repos/realm/realm-java/issues/6169","id":423465234,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzQ2NTIzNA==","user":{"login":"Zhuinden","id":11718392,"node_id":"MDQ6VXNlcjExNzE4Mzky","avatar_url":"https://avatars1.githubusercontent.com/u/11718392?v=4","gravatar_id":"","url":"https://api.github.com/users/Zhuinden","html_url":"https://github.com/Zhuinden","followers_url":"https://api.github.com/users/Zhuinden/followers","following_url":"https://api.github.com/users/Zhuinden/following{/other_user}","gists_url":"https://api.github.com/users/Zhuinden/gists{/gist_id}","starred_url":"https://api.github.com/users/Zhuinden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zhuinden/subscriptions","organizations_url":"https://api.github.com/users/Zhuinden/orgs","repos_url":"https://api.github.com/users/Zhuinden/repos","events_url":"https://api.github.com/users/Zhuinden/events{/privacy}","received_events_url":"https://api.github.com/users/Zhuinden/received_events","type":"User","site_admin":false},"created_at":"2018-09-21T09:00:46Z","updated_at":"2018-09-21T09:00:46Z","author_association":"CONTRIBUTOR","body":"Keep in mind that `Kotlin-Realm-Extensions` is not an official Realm library"}}
{"actor":{"display_login":"Zhuinden"}}