Title: StackOverflow in JSONObject · Issue #264 · stleary/JSON-java · GitHub
Open Graph Title: StackOverflow in JSONObject · Issue #264 · stleary/JSON-java
X Title: StackOverflow in JSONObject · Issue #264 · stleary/JSON-java
Description: I noticed this when updating one of the libraries in our project. I used to serialise a dto which extends another one. This super class has a getter returning an Apache FastDateFormat, which is a singleton and returning a static instance...
Open Graph Description: I noticed this when updating one of the libraries in our project. I used to serialise a dto which extends another one. This super class has a getter returning an Apache FastDateFormat, which is a s...
X Description: I noticed this when updating one of the libraries in our project. I used to serialise a dto which extends another one. This super class has a getter returning an Apache FastDateFormat, which is a s...
Opengraph URL: https://github.com/stleary/JSON-java/issues/264
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"StackOverflow in JSONObject","articleBody":"I noticed this when updating one of the libraries in our project. I used to serialise a dto which extends another one. This super class has a getter returning an Apache `FastDateFormat`, which is a singleton and returning a static instance of itself.\n\nPreviously this wasn't an issue because the JSONObject (JSONArray in my case) took a boolean specifying whether to `includeSuperClass` or not. By default, that was `false` and only the child class was serialised. The parameter is now gone and the default behaviour is that the super class is serialised as well. Hence my issue came up.\n\nGiven this class\n\n``` java\npublic class StackOverflow {\n\n public static void main(String[] args) {\n // final org.apache.commons.lang.time.FastDateFormat fdf = org.apache.commons.lang.time.FastDateFormat.getInstance();\n final MyDto dto = new MyDto(\"myvalue\");\n new org.json.JSONObject(dto);\n }\n}\n```\n\nWhich uses these\n\n``` java\npublic class MyDto {\n\n private String value1;\n private StaticMethodClass smc = StaticMethodClass.getInstance();\n\n public MyDto(String value1) { this.value1 = value1; }\n public String getValue1() { return value1; }\n public void setValue1(String value1) { this.value1 = value1; }\n public StaticMethodClass getSmc() { return smc; }\n public void setSmc(StaticMethodClass smc) { this.smc = smc; }\n}\n\npublic class StaticMethodClass {\n\n private static StaticMethodClass _instance;\n\n private StaticMethodClass() {}\n\n public static StaticMethodClass getInstance() {\n if (_instance == null) _instance = new StaticMethodClass();\n return _instance;\n }\n}\n```\n\nSerializing the `getInstance` method will cause a stack overflow in JSONObject since it keeps being wrapped in JSONObjects (In theory, you can keep doing StaticMethodClass.getInstance().getInstance().getInstance().getInstance()...)\n\nOf course, serialising an instance of StaticMethodClass would cause a Stackoverflow as well.\n","author":{"url":"https://github.com/auricgoldfinger","@type":"Person","name":"auricgoldfinger"},"datePublished":"2016-08-10T07:01:19Z","url":"https://github.com/stleary/JSON-java/issues/264"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:15d3d36f-7ff6-63c2-2b22-f00feb17bd67 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9C54:2E24C3:21DFA1D:2F33E08:6AFD2C09 |
| html-safe-nonce | 84781b840f97d7956bb21a75dc18a69a18794e5718792f4a1ce8b7ecb1609f58 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QzU0OjJFMjRDMzoyMURGQTFEOjJGMzNFMDg6NkFGRDJDMDkiLCJ2aXNpdG9yX2lkIjoiNDYzNDk3OTU3MzQ4ODc1Nzc2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6be64010ddc2fcf3dd7df45d3d182cb677e268f31f126c078497b5974338a021 |
| hovercard-subject-tag | issue:170343408 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/stleary/JSON-java/264/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f59262f7c73470233e53562d01c452f0384712a0d8fb3167d4802f3c6d6e19f6/stleary/JSON-java/issues/264 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f59262f7c73470233e53562d01c452f0384712a0d8fb3167d4802f3c6d6e19f6/stleary/JSON-java/issues/264 |
| og:image:alt | I noticed this when updating one of the libraries in our project. I used to serialise a dto which extends another one. This super class has a getter returning an Apache FastDateFormat, which is a s... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | auricgoldfinger |
| hostname | github.com |
| expected-hostname | github.com |
| None | 065128366c233a9d57ff68ab6c96e25b99dd1b0ab70d23b70873d3dd6b5e4f19 |
| turbo-cache-control | no-preview |
| go-import | github.com/stleary/JSON-java git https://github.com/stleary/JSON-java.git |
| octolytics-dimension-user_id | 5107558 |
| octolytics-dimension-user_login | stleary |
| octolytics-dimension-repository_id | 1187853 |
| octolytics-dimension-repository_nwo | stleary/JSON-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1187853 |
| octolytics-dimension-repository_network_root_nwo | stleary/JSON-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 941021edf0c2ec58298f4a2c8f27ae507d129c92 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width