Uploaded image for project: 'Tapestry 5'
  1. Tapestry 5
  2. TAP5-2640

tapestry-json improvements (implement Collection/Map, better exceptions)

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 5.6.2, 5.7.0
    • tapestry-json
    • None

    Description

      As laid out in http://mail-archives.apache.org/mod_mbox/tapestry-dev/202007.mbox/browser these patches aim to improve tapestry-json.

      Core features:

      • JSONArray/JSONObject implements Collection/Map
      • Better exceptions

      Unit-tests were added if appropiate. "Passthrough"-methods to the underlying storage weren't tested if there are no additional edge-cases.

      Javadoc was added, trying to mimic Collection/Map, but reduced to the actual exception cases.

      Minar/breaking changes occur as discussed on the mailing list:

      • Signature change: JSONObject get(Object name) instead of JSONObject get(String name)
      • Return type / Signature change: void putAll(Map<? extends String, ? extends Object> newProperties) instead of JSONObject putAll(Map<String, ?> newProperties)

      I've attached 21 patch files. Maybe I should've squashed it, but if anyone is interested in the evolution/idea behind the code, this way it would be easier to grasp it.

      The code is also available on Github https://github.com/apache/tapestry-5/compare/master...benweidig:feature/tapestry-json-exceptions

      Attachments

        1. 0005-tapestry-json-JSONTokener-constructors-exceptions-im.patch
          3 kB
          Ben Weidig
        2. 0004-tapestry-json-JSONArray-get-now-throws-IndexOutOfBou.patch
          3 kB
          Ben Weidig
        3. 0001-tapestry-json-adding-JSONInvalidTypeException.patch
          12 kB
          Ben Weidig
        4. 0009-tapesty-json-javadoc-updated.patch
          3 kB
          Ben Weidig
        5. 0002-travis-disabled-mail-notification.patch
          0.5 kB
          Ben Weidig
        6. 0007-tapestry-json-better-exception-building.patch
          16 kB
          Ben Weidig
        7. 0013-tapestry-json-code-style.patch
          0.9 kB
          Ben Weidig
        8. 0012-tapestry-json-added-JSONArrayIndexOutOfBoundsExcepti.patch
          5 kB
          Ben Weidig
        9. 0008-tapestry-json-added-JSONSyntaxException.patch
          9 kB
          Ben Weidig
        10. 0014-tapestrsy-json-fix-lossy-conversion.patch
          2 kB
          Ben Weidig
        11. 0010-tapestry-json-JSONArray-non-finite-nan-check-fixed.patch
          2 kB
          Ben Weidig
        12. 0015-tapestry-json-source-formatting.patch
          11 kB
          Ben Weidig
        13. 0011-tapestry-json-javadoc-typo.patch
          1 kB
          Ben Weidig
        14. 0020-tapestry-json-JSONArray-improve-javadoc.patch
          7 kB
          Ben Weidig
        15. 0017-tapestry-json-JSONObject-implements-Map-String-Objec.patch
          12 kB
          Ben Weidig
        16. 0019-tapestry-json-make-JSONArray-a-real-Collection-wip.patch
          16 kB
          Ben Weidig
        17. 0016-tapestry-json-throw-IllegalArgumentException-on-inva.patch
          4 kB
          Ben Weidig
        18. 0018-tapestry-json-added-get-type-OrDefault-methods-to-JS.patch
          8 kB
          Ben Weidig
        19. 0021-tapestry-json-JSONObject-improve-javadoc.patch
          10 kB
          Ben Weidig
        20. 0006-tapestry-json-improve-JSONSpec-tests.patch
          2 kB
          Ben Weidig
        21. 0003-tapestry-json-added-JSONTypeMismatchException.patch
          25 kB
          Ben Weidig

        Issue Links

          Activity

            Commit 2dab8e0ad16c1ad690e08f9eb76fe2a42b187b3d in tapestry-5's branch refs/heads/master from Benjamin Weidig
            [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=2dab8e0 ]

            TAP5-2640: tapestry-json improvements

            (implement Collection/Map, better exceptions)

            tapestry-json: added JSONTypeMismatchException

            Added JSONTypeMismatchException and JSONValueNotFoundException. JSONObject behaviour improved by using opt() isntead of get for mor specific types, so we can actually use the new exceptions.

            tapestry-json: JSONArray get() now throws IndexOutOfBoundsException

            There's no reason to repackage the original exception into a RuntimeException.

            tapestry-json: JSONTokener constructors exceptions improved

            tapestry-json: improve JSONSpec tests

            tapestry-json: better exception building

            tapestry-json: added JSONSyntaxException

            tapesty-json: javadoc updated

            tapestry-json: JSONArray non-finite/nan check fixed

            The constructor wasn't using checkedPut, even though the javadoc states that doubles are checked.

            tapestry-json: javadoc typo

            tapestry-json: added JSONArrayIndexOutOfBoundsException

            tapestry-json: code style

            tapestrsy-json: fix lossy conversion

            tapestry-json: source formatting

            tapestry-json: throw IllegalArgumentException on invalid doubles

            tapestry-json: JSONObject implements Map<String, Object>

            To provide better interoperability with Java collections the JSONObject type now implements Map<String, Object>.

            The needed changes are marginal:

            • putAll -> now returns void (breaking change)
            • Arguments for key are Object -> shouldn't be a problem

            tapestry-json: added get

            {type}

            OrDefault methods to JSONObject

            tapestry-json: make JSONArray a "real" Collection (wip)

            tapestry-json: JSONArray improve javadoc

            tapestry-json: JSONObject improve javadoc

            jira-bot ASF subversion and git services added a comment - Commit 2dab8e0ad16c1ad690e08f9eb76fe2a42b187b3d in tapestry-5's branch refs/heads/master from Benjamin Weidig [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=2dab8e0 ] TAP5-2640 : tapestry-json improvements (implement Collection/Map, better exceptions) tapestry-json: added JSONTypeMismatchException Added JSONTypeMismatchException and JSONValueNotFoundException. JSONObject behaviour improved by using opt() isntead of get for mor specific types, so we can actually use the new exceptions. tapestry-json: JSONArray get() now throws IndexOutOfBoundsException There's no reason to repackage the original exception into a RuntimeException. tapestry-json: JSONTokener constructors exceptions improved tapestry-json: improve JSONSpec tests tapestry-json: better exception building tapestry-json: added JSONSyntaxException tapesty-json: javadoc updated tapestry-json: JSONArray non-finite/nan check fixed The constructor wasn't using checkedPut, even though the javadoc states that doubles are checked. tapestry-json: javadoc typo tapestry-json: added JSONArrayIndexOutOfBoundsException tapestry-json: code style tapestrsy-json: fix lossy conversion tapestry-json: source formatting tapestry-json: throw IllegalArgumentException on invalid doubles tapestry-json: JSONObject implements Map<String, Object> To provide better interoperability with Java collections the JSONObject type now implements Map<String, Object>. The needed changes are marginal: putAll -> now returns void (breaking change) Arguments for key are Object -> shouldn't be a problem tapestry-json: added get {type} OrDefault methods to JSONObject tapestry-json: make JSONArray a "real" Collection (wip) tapestry-json: JSONArray improve javadoc tapestry-json: JSONObject improve javadoc
            hudson Hudson added a comment -

            FAILURE: Integrated in Jenkins build Tapestry » tapestry-trunk-freestyle #10 (See https://ci-builds.apache.org/job/Tapestry/job/tapestry-trunk-freestyle/10/)
            TAP5-2640: tapestry-json improvements (thiago: rev 2dab8e0ad16c1ad690e08f9eb76fe2a42b187b3d)

            • (add) tapestry-json/src/test/groovy/json/specs/JSONSpec.groovy
            • (add) tapestry-json/src/main/java/org/apache/tapestry5/json/exceptions/JSONSyntaxException.java
            • (edit) tapestry-json/src/test/groovy/json/specs/JSONArraySpec.groovy
            • (add) tapestry-json/src/main/java/org/apache/tapestry5/json/exceptions/JSONValueNotFoundException.java
            • (edit) tapestry-json/src/test/groovy/json/specs/JSONObjectSpec.groovy
            • (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
            • (add) tapestry-json/src/main/java/org/apache/tapestry5/json/exceptions/JSONArrayIndexOutOfBoundsException.java
            • (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSON.java
            • (add) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONType.java
            • (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONArray.java
            • (add) tapestry-json/src/main/java/org/apache/tapestry5/json/exceptions/JSONTypeMismatchException.java
            • (add) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONExceptionBuilder.java
            • (add) tapestry-json/src/main/java/org/apache/tapestry5/json/exceptions/JSONInvalidTypeException.java
            • (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONTokener.java
            hudson Hudson added a comment - FAILURE: Integrated in Jenkins build Tapestry » tapestry-trunk-freestyle #10 (See https://ci-builds.apache.org/job/Tapestry/job/tapestry-trunk-freestyle/10/ ) TAP5-2640 : tapestry-json improvements (thiago: rev 2dab8e0ad16c1ad690e08f9eb76fe2a42b187b3d) (add) tapestry-json/src/test/groovy/json/specs/JSONSpec.groovy (add) tapestry-json/src/main/java/org/apache/tapestry5/json/exceptions/JSONSyntaxException.java (edit) tapestry-json/src/test/groovy/json/specs/JSONArraySpec.groovy (add) tapestry-json/src/main/java/org/apache/tapestry5/json/exceptions/JSONValueNotFoundException.java (edit) tapestry-json/src/test/groovy/json/specs/JSONObjectSpec.groovy (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java (add) tapestry-json/src/main/java/org/apache/tapestry5/json/exceptions/JSONArrayIndexOutOfBoundsException.java (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSON.java (add) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONType.java (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONArray.java (add) tapestry-json/src/main/java/org/apache/tapestry5/json/exceptions/JSONTypeMismatchException.java (add) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONExceptionBuilder.java (add) tapestry-json/src/main/java/org/apache/tapestry5/json/exceptions/JSONInvalidTypeException.java (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONTokener.java

            Commit a1ba6d470808d9fb3588efc24e945ce01de1357c in tapestry-5's branch refs/heads/master from Thiago H. de Paula Figueiredo
            [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=a1ba6d4 ]

            TAP5-2640: fixing JavaDoc errors.

            jira-bot ASF subversion and git services added a comment - Commit a1ba6d470808d9fb3588efc24e945ce01de1357c in tapestry-5's branch refs/heads/master from Thiago H. de Paula Figueiredo [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=a1ba6d4 ] TAP5-2640 : fixing JavaDoc errors.
            hudson Hudson added a comment -

            FAILURE: Integrated in Jenkins build Tapestry » tapestry-trunk-freestyle #11 (See https://ci-builds.apache.org/job/Tapestry/job/tapestry-trunk-freestyle/11/)
            TAP5-2640: fixing JavaDoc errors. (thiago: rev a1ba6d470808d9fb3588efc24e945ce01de1357c)

            • (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
            • (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONArray.java
            hudson Hudson added a comment - FAILURE: Integrated in Jenkins build Tapestry » tapestry-trunk-freestyle #11 (See https://ci-builds.apache.org/job/Tapestry/job/tapestry-trunk-freestyle/11/ ) TAP5-2640 : fixing JavaDoc errors. (thiago: rev a1ba6d470808d9fb3588efc24e945ce01de1357c) (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONArray.java

            Thank you very much, ben-ng! Your implementation has been merged to master.

            thiagohp Thiago Henrique De Paula Figueiredo added a comment - Thank you very much, ben-ng ! Your implementation has been merged to master.

            Commit f68f13545422f2a7f41414706a148b1780ec56eb in tapestry-5's branch refs/heads/5.6.x from Benjamin Weidig
            [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=f68f135 ]

            TAP5-2640: tapestry-json improvements

            (implement Collection/Map, better exceptions)

            tapestry-json: added JSONTypeMismatchException

            Added JSONTypeMismatchException and JSONValueNotFoundException. JSONObject behaviour improved by using opt() isntead of get for mor specific types, so we can actually use the new exceptions.

            tapestry-json: JSONArray get() now throws IndexOutOfBoundsException

            There's no reason to repackage the original exception into a RuntimeException.

            tapestry-json: JSONTokener constructors exceptions improved

            tapestry-json: improve JSONSpec tests

            tapestry-json: better exception building

            tapestry-json: added JSONSyntaxException

            tapesty-json: javadoc updated

            tapestry-json: JSONArray non-finite/nan check fixed

            The constructor wasn't using checkedPut, even though the javadoc states that doubles are checked.

            tapestry-json: javadoc typo

            tapestry-json: added JSONArrayIndexOutOfBoundsException

            tapestry-json: code style

            tapestrsy-json: fix lossy conversion

            tapestry-json: source formatting

            tapestry-json: throw IllegalArgumentException on invalid doubles

            tapestry-json: JSONObject implements Map<String, Object>

            To provide better interoperability with Java collections the JSONObject type now implements Map<String, Object>.

            The needed changes are marginal:

            • putAll -> now returns void (breaking change)
            • Arguments for key are Object -> shouldn't be a problem

            tapestry-json: added get

            {type}

            OrDefault methods to JSONObject

            tapestry-json: make JSONArray a "real" Collection (wip)

            tapestry-json: JSONArray improve javadoc

            tapestry-json: JSONObject improve javadoc

            jira-bot ASF subversion and git services added a comment - Commit f68f13545422f2a7f41414706a148b1780ec56eb in tapestry-5's branch refs/heads/5.6.x from Benjamin Weidig [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=f68f135 ] TAP5-2640 : tapestry-json improvements (implement Collection/Map, better exceptions) tapestry-json: added JSONTypeMismatchException Added JSONTypeMismatchException and JSONValueNotFoundException. JSONObject behaviour improved by using opt() isntead of get for mor specific types, so we can actually use the new exceptions. tapestry-json: JSONArray get() now throws IndexOutOfBoundsException There's no reason to repackage the original exception into a RuntimeException. tapestry-json: JSONTokener constructors exceptions improved tapestry-json: improve JSONSpec tests tapestry-json: better exception building tapestry-json: added JSONSyntaxException tapesty-json: javadoc updated tapestry-json: JSONArray non-finite/nan check fixed The constructor wasn't using checkedPut, even though the javadoc states that doubles are checked. tapestry-json: javadoc typo tapestry-json: added JSONArrayIndexOutOfBoundsException tapestry-json: code style tapestrsy-json: fix lossy conversion tapestry-json: source formatting tapestry-json: throw IllegalArgumentException on invalid doubles tapestry-json: JSONObject implements Map<String, Object> To provide better interoperability with Java collections the JSONObject type now implements Map<String, Object>. The needed changes are marginal: putAll -> now returns void (breaking change) Arguments for key are Object -> shouldn't be a problem tapestry-json: added get {type} OrDefault methods to JSONObject tapestry-json: make JSONArray a "real" Collection (wip) tapestry-json: JSONArray improve javadoc tapestry-json: JSONObject improve javadoc

            Commit 917e4719aed2c2f853fefc68207aa7249d87365f in tapestry-5's branch refs/heads/5.6.x from Thiago H. de Paula Figueiredo
            [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=917e471 ]

            TAP5-2640: fixing JavaDoc errors.

            jira-bot ASF subversion and git services added a comment - Commit 917e4719aed2c2f853fefc68207aa7249d87365f in tapestry-5's branch refs/heads/5.6.x from Thiago H. de Paula Figueiredo [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=917e471 ] TAP5-2640 : fixing JavaDoc errors.

            Commit dbd66fdec13319e04ebf5d8a18db906f19ae7bf1 in tapestry-5's branch refs/heads/master from Benjamin Weidig
            [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=dbd66fd ]

            TAP5-2640: Added JSONCollectors, modified JSONObject#merge

            For simpler usage with streams the class JSONCollectors provides static helper methods.

            During testing it became clear that the default Map#merge(...) wasn't viable for the general JSONObject logic (exception on unknow keys), so it had to be overriden and adapted.

            jira-bot ASF subversion and git services added a comment - Commit dbd66fdec13319e04ebf5d8a18db906f19ae7bf1 in tapestry-5's branch refs/heads/master from Benjamin Weidig [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=dbd66fd ] TAP5-2640 : Added JSONCollectors, modified JSONObject#merge For simpler usage with streams the class JSONCollectors provides static helper methods. During testing it became clear that the default Map#merge(...) wasn't viable for the general JSONObject logic (exception on unknow keys), so it had to be overriden and adapted.
            hudson Hudson added a comment -

            FAILURE: Integrated in Jenkins build Tapestry » tapestry-trunk-freestyle #59 (See https://ci-builds.apache.org/job/Tapestry/job/tapestry-trunk-freestyle/59/)
            TAP5-2640: Added JSONCollectors, modified JSONObject#merge (ben: rev dbd66fdec13319e04ebf5d8a18db906f19ae7bf1)

            • (add) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONCollectors.java
            • (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
            • (add) tapestry-json/src/test/groovy/json/specs/JSONCollectorsSpec.groovy
            • (edit) 5.7_RELEASE_NOTES.md
            hudson Hudson added a comment - FAILURE: Integrated in Jenkins build Tapestry » tapestry-trunk-freestyle #59 (See https://ci-builds.apache.org/job/Tapestry/job/tapestry-trunk-freestyle/59/ ) TAP5-2640 : Added JSONCollectors, modified JSONObject#merge (ben: rev dbd66fdec13319e04ebf5d8a18db906f19ae7bf1) (add) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONCollectors.java (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java (add) tapestry-json/src/test/groovy/json/specs/JSONCollectorsSpec.groovy (edit) 5.7_RELEASE_NOTES.md

            Commit a952dd857e8618febe391ab8ad6563ef9e86e578 in tapestry-5's branch refs/heads/master from Benjamin Weidig
            [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=a952dd8 ]

            TAP5-2640: Fixing JSONCollectors generic method signatures

            jira-bot ASF subversion and git services added a comment - Commit a952dd857e8618febe391ab8ad6563ef9e86e578 in tapestry-5's branch refs/heads/master from Benjamin Weidig [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=a952dd8 ] TAP5-2640 : Fixing JSONCollectors generic method signatures

            Commit 365a0eb6977be4014ad9193973e391899aa31081 in tapestry-5's branch refs/heads/master from Benjamin Weidig
            [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=365a0eb ]

            TAP5-2640: Fixing JavaDoc errors

            jira-bot ASF subversion and git services added a comment - Commit 365a0eb6977be4014ad9193973e391899aa31081 in tapestry-5's branch refs/heads/master from Benjamin Weidig [ https://gitbox.apache.org/repos/asf?p=tapestry-5.git;h=365a0eb ] TAP5-2640 : Fixing JavaDoc errors
            hudson Hudson added a comment -

            SUCCESS: Integrated in Jenkins build Tapestry » tapestry-trunk-freestyle #60 (See https://ci-builds.apache.org/job/Tapestry/job/tapestry-trunk-freestyle/60/)
            TAP5-2640: Fixing JSONCollectors generic method signatures (ben: rev a952dd857e8618febe391ab8ad6563ef9e86e578)

            • (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONCollectors.java
              TAP5-2640: Fixing JavaDoc errors (ben: rev 365a0eb6977be4014ad9193973e391899aa31081)
            • (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONCollectors.java
            hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build Tapestry » tapestry-trunk-freestyle #60 (See https://ci-builds.apache.org/job/Tapestry/job/tapestry-trunk-freestyle/60/ ) TAP5-2640 : Fixing JSONCollectors generic method signatures (ben: rev a952dd857e8618febe391ab8ad6563ef9e86e578) (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONCollectors.java TAP5-2640 : Fixing JavaDoc errors (ben: rev 365a0eb6977be4014ad9193973e391899aa31081) (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONCollectors.java

            People

              ben-ng Ben Weidig
              ben-ng Ben Weidig
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: