Giter VIP home page Giter VIP logo

Comments (2)

rowstop avatar rowstop commented on June 9, 2024
    /**
     * 引用检测 测试
     * todo: 未通过 ❌ 应该使用兼容性更好的 $['key'] 👀 而不是 $.key 作为引用路径
     */
    @Test
    void testReferenceDetection() {
        //不支持 ❌ ref -> $.2024-01-22 16:39:40.328
        String json = "{\"2024-01-22 16:39:40.328\":{\"name\":\"jsonObject1\"},\"{\\\"name\\\":\\\"key\\\"}\":{\"$ref\":\"$.2024-01-22 16:39:40.328\"}}";
        JSONObject jsonObject1 = JSON.parseObject(json);
        //支持 👍 ref -> $['2024-01-22 16:39:40.328']
        json = "{\"2024-01-22 16:39:40.328\":{\"name\":\"jsonObject2\"},\"{\\\"name\\\":\\\"key\\\"}\":{\"$ref\":\"$['2024-01-22 16:39:40.328']\"}}";
        JSONObject jsonObject2 = JSON.parseObject(json);
        //不支持 ❌ ref -> $.{\"name\":\"key\"}"}
        json = "{\"{\\\"name\\\":\\\"key\\\"}\":{\"name\":\"jsonObject3\"},\"2024-01-22 16:39:40.328\":{\"$ref\":\"$.{\\\"name\\\":\\\"key\\\"}\"}}";
        JSONObject jsonObject3 = JSON.parseObject(json);
        //支 持 👍  ref -> $['{\"name\":\"key\"}']
        json = "{\"{\\\"name\\\":\\\"key\\\"}\":{\"name\":\"jsonObject4\"},\"2024-01-22 15:50:24.525\":{\"$ref\":\"$['{\\\"name\\\":\\\"key\\\"}']\"}}";
        JSONObject jsonObject4 = JSON.parseObject(json);
        //支持 👍 ref -> $.null
        json = "{\"null\":{\"name\":\"jsonObject5\"},\"2024-01-22 15:50:24.525\":{\"$ref\":\"$.null\"}}";
        JSONObject jsonObject5 = JSON.parseObject(json);
        //支持 👍 ref -> $['null']
        json = "{\"null\":{\"name\":\"jsonObject6\"},\"2024-01-22 15:50:24.525\":{\"$ref\":\"$['null']\"}}";
        JSONObject jsonObject6 = JSON.parseObject(json);
        //不支持 ❌ ref -> $.1
        json = "{1:{\"name\":\"jsonObject7\"},\"2024-01-22 15:50:24.525\":{\"$ref\":\"$.1\"}}";
        JSONObject jsonObject7 = JSON.parseObject(json,JSONReader.Feature.AllowUnQuotedFieldNames);
        //支持 👍 ref -> $[1]
        json = "{1:{\"name\":\"jsonObject8\"},\"2024-01-22 15:50:24.525\":{\"$ref\":\"$[1]\"}}";
        JSONObject jsonObject8 = JSON.parseObject(json,JSONReader.Feature.AllowUnQuotedFieldNames);
        //支持 👍 ref -> $.1
        json = "{\"1\":{\"name\":\"jsonObject9\"},\"2024-01-22 15:50:24.525\":{\"$ref\":\"$.1\"}}";
        JSONObject jsonObject9 = JSON.parseObject(json);
        //支持 👍 ref -> $[1]
        json = "{\"1\":{\"name\":\"jsonObject10\"},\"2024-01-22 15:50:24.525\":{\"$ref\":\"$[1]\"}}";
        JSONObject jsonObject10 = JSON.parseObject(json);
    }

from fastjson2.

wenshao avatar wenshao commented on June 9, 2024

这样确实更好,但改动比较大,对旧版的兼容也会不好

from fastjson2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.