Repository navigation
Commit 88b6be9
committed
Clarify fromJson(Class) Javadoc: type registry does not exist
The fromJson(Class) Javadoc claimed that only classes "explicitly supported
and registered within the JSONObject context" can be deserialized, and
declared an IllegalArgumentException for classes outside that set. No such
registry exists: fromJson instantiates any class with a no-arg constructor and
writes every non-static declared field whose name matches a JSON key, widening
access with setAccessible(true). Private and transient fields are populated,
and JSONPropertyIgnore does not apply because it only suppresses the bean to
JSONObject direction.
The binding rules are already released, so changing them here would break
existing users. Instead document what actually happens, point out that binding
is driven by whatever keys the JSON contains, and replace the non-existent
IllegalArgumentException with the JSONException the method really throws.
Adds JSONObjectTest#jsonObjectParseFromJson_10 to pin the current binding
behavior so the documentation cannot drift from the implementation again. The
test bean is named FromJsonKeyBindingExample and its fields spell out how they
are declared (privateString, privateBoolean, transientString,
ignoredGetterBoolean), so the test reads as a binding example rather than as a
scenario.
Fixes #10761 parent 69383f7 commit 88b6be9
3 files changed
Lines changed: 79 additions & 6 deletions
File tree
- src
- main/java/org/json
- test/java/org/json/junit
- data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3472 | 3472 | | |
3473 | 3473 | | |
3474 | 3474 | | |
3475 | | - | |
| 3475 | + | |
| 3476 | + | |
3476 | 3477 | | |
3477 | 3478 | | |
3478 | 3479 | | |
3479 | 3480 | | |
3480 | 3481 | | |
| 3482 | + | |
| 3483 | + | |
3481 | 3484 | | |
3482 | 3485 | | |
3483 | 3486 | | |
| |||
3493 | 3496 | | |
3494 | 3497 | | |
3495 | 3498 | | |
3496 | | - | |
3497 | | - | |
3498 | | - | |
3499 | | - | |
| 3499 | + | |
| 3500 | + | |
| 3501 | + | |
| 3502 | + | |
| 3503 | + | |
| 3504 | + | |
| 3505 | + | |
| 3506 | + | |
3500 | 3507 | | |
3501 | 3508 | | |
3502 | 3509 | | |
3503 | 3510 | | |
3504 | | - | |
| 3511 | + | |
| 3512 | + | |
3505 | 3513 | | |
3506 | 3514 | | |
3507 | 3515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
3883 | 3884 | | |
3884 | 3885 | | |
3885 | 3886 | | |
| 3887 | + | |
| 3888 | + | |
| 3889 | + | |
| 3890 | + | |
| 3891 | + | |
| 3892 | + | |
| 3893 | + | |
| 3894 | + | |
| 3895 | + | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
| 3900 | + | |
| 3901 | + | |
| 3902 | + | |
| 3903 | + | |
| 3904 | + | |
| 3905 | + | |
| 3906 | + | |
| 3907 | + | |
| 3908 | + | |
| 3909 | + | |
| 3910 | + | |
| 3911 | + | |
3886 | 3912 | | |
3887 | 3913 | | |
3888 | 3914 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
0 commit comments