|
Meta tags:
description=Description
Fixes #1076.
The fromJson(Class) Javadoc documented a protection that was never implemented:
Only classes that are explicitly supported and registered within the JSONObject context can be deserialized ... This ensures that only a limited and controlled set of types can be instantiated from JSON for safety and predictability.
There is no registry anywhere in the source. The method calls setAccessible(true) on every non-static declared field and writes it when its name matches a key in the JSON, so private, transient and @JSONPropertyIgnore-exposed fields are all populated from whatever keys the input contains. The @throws IllegalArgumentException line was wrong too: nothing in the method throws it, failures surface as JSONException.
Since the binding rules themselves are already released, this PR leaves them untouched, per #1076 (comment), and only makes the Javadoc match reality:
the registry paragraph is replaced with what actually happens, including a note that key-driven binding means untrusted JSON should be validated, or reduced to the expected keys, before being passed in
@throws IllegalArgumentException is replaced with the JSONException the method throws when the class has no accessible no-arg constructor or a field cannot be set
the static fromJson(String, Class) now links to those rules instead of silently inheriting them
Tests
JSONObjectTest#jsonObjectParseFromJson_10 binds a bean with a private admin, a private tenantId, a transient sessionKey and a superAdmin hidden behind an @JSONPropertyIgnore getter. It asserts all four are populated, which is the behavior the Javadoc now describes. This is a characterization test: it passes before and after the change, and exists so the documentation cannot drift from the implementation again without a failing test.
mvn test
Tests run: 825, Failures: 0, Errors: 0, Skipped: 6
mvn javadoc:javadoc succeeds, so the new @link references and HTML are valid.
No behavior change.;
Headings (most frequently used words):
uh, oh, for, navigation, update, javadocs, fromjson, 1095, footer, diff, view, menu, repository, there, are, no, files, selected, viewing, filter, by, extension,
Text of the page (most frequently used words):
the (45), json (28), and (26), file (25), class (21), java (21), code (19), this (17), org (17), github (16), for (16), jsonobject (14), #fromjson (14), field (14), public (13), string (13), junit (13), that (12), line (12), private (12), applied (11), hidden (11), fields (11), all (10), not (9), cannot (9), reload (9), data (9), show (9), characters (9), unicode (9), from (8), fromjsonkeybindingexample (8), are (8), import (8), diff (8), test (8), populated (8), type (8), you (7), suggestion (7), suggestions (7), while (7), changes (7), loading (7), return (7), transient (7), open (7), src (7), expand (7), bound (7), object (7), sign (7), can (6), only (6), boolean (6), jsonpropertyignore (6), with (6), number (6), bidirectional (6), static (6), clazz (6), security (5), please (5), comments (5), must (5), commit (5), there (5), down (5), keys (5), learn (5), about (5), view (5), should (5), put (5), param (5), jsonstring (5), your (5), pull (4), change (4), was (4), error (4), page (4), ignoredgetterboolean (4), transientstring (4), privatestring (4), privateboolean (4), bean (4), how (4), what (4), review (4), more (4), new (4), assertequals (4), true (4), value (4), declared (4), link (4), strong (4), files (4), stleary (4), support (4), copilot (4), community (3), navigation (3), 2026 (3), request (3), supported (3), add (3), batch (3), retry (3), direction (3), behind (3), getter (3), original (3), contains (3), text (3), may (3), interpreted (3), compiled (3), differently (3), than (3), appears (3), below (3), editor (3), reveals (3), desktop (3), delete (3), edit (3), additions (3), deletions (3), jsonparserconfiguration (3), void (3), see (3), issue (3), binding (3), jsonobjecttest (3), throws (3), argument (3), constructor (3), its (3), have (3), main (3), hide (3), whitespace (3), filter (3), lyin (3), ottf (3), commits (3), 1095 (3), update (3), javadocs (3), merged (3), account (3), quality (3), another (3), tab (3), window (3), refresh (3), session (3), developers (3), changelog (3), customer (3), enterprise (3), grade (3), features (3), build (3), contact (2), status (2), privacy (2), terms (2), footer (2), has (2), valid (2), single (2), one (2), viewing (2), because (2), toggle (2), isignoredgetterboolean (2), gettransientstring (2), getprivatestring (2), isprivateboolean (2), displayname (2), suppresses (2), 1076 (2), name (2), matches (2), key (2), written (2), every (2), non (2), instantiated (2), set (2), jsonexception (2), instance (2), returned (2), method (2), source (2), does (2), including (2), note (2), types (2), ignored (2), names (2), match (2), 3472 (2), selected (2), apply (2), split (2), unified (2), failed (2), load (2), jump (2), extension (2), oct (2), javadoc (2), tree (2), insights (2), projects (2), actions (2), repository (2), signed (2), universe (2), training (2), integrations (2), stories (2), center (2), documentation (2), business (2), fixes (2), products (2), secret (2), perform, action, time, share, personal, information, manage, cookies, docs, inc, right, now, check, back, later, queued, merge, multi, pending, reviews, been, marked, resolved, outdated, existing, order, create, applying, deleted, lines, per, subset, closed, invalid, were, made, annotations, notes, oops, something, went, wrong, required, tests, annotated, which, used, pin, binds, package, testmaxnumberlength, bob, jsonobjectparsefromjson_10, annotation, affects, whose, matter, pins, done, 3883, 3884, jsonobjectparsefromjson_9, ignore, after, customclassj, customclassi, customclassh, suppresswarnings, unchecked, accessible, illegalargumentexception, deserialization, validated, reduced, expected, before, handed, being, here, coming, untrusted, therefore, keep, lang, reflect, setaccessible, access, widened, when, driven, present, controlled, safety, predictability, will, able, deserialize, ensures, limited, context, deserialized, provided, among, those, classes, explicitly, registered, within, target, 3493, 3496, described, format, remaining, long, well, their, boxed, counterparts, given, supports, basic, int, double, float, getmaptypes, conversations, clear, filters, viewed, nbsp, clarify, registry, exist, 88b6be9, select, changed, checks, conversation, into, fix, master, already, clicking, agree, our, occasionally, send, related, emails, statement, service, free, maintainers, question, project, items, wiki, requests, issues, message, dismiss, alert, switched, accounts, out, appearance, settings, search, pricing, event, talks, workshops, next, partners, company, forum, events, webinars, blog, resource, connect, resources, premium, advanced, ons, trust, why, evaluate, industries, government, manufacturing, financial, services, healthcare, industry, nonprofits, startups, small, medium, teams, enterprises, stage, businesses, latest, improvements, across, place, developer, articles, sponsors, trending, repos, explore, customize, certifications, scanning, leak, prevention, protection, vulnerability, detection, remediation, secure, cloud, development, environments, codespaces, analysis, enforcement, automation, ship, coding, agent, tasks, automated, work, hosting, collaboration, platform, menu, skip, content,
|