LazyJSON icon indicating copy to clipboard operation
LazyJSON copied to clipboard

Bug manipulating LazyArray

Open SGE66 opened this issue 2 years ago • 0 comments

Execute following code:

        LazyArray records = new LazyArray("[{\"id\": \"20\"}]");
        LazyArray activities =  new LazyArray("[{\"id\": \"30\"}]");
        
        LazyArray tmp = new LazyArray();
        for (int i = 0; i < records.length(); i++) {
            tmp.put(records.getJSONObject(i));
        }
        for (int i = 0; i < activities.length(); i++) {
            tmp.put(activities.getJSONObject(i));
        }
                
        System.out.println("-- tmp (no pad) -- ");
        System.out.println(tmp.length());
        System.out.println(tmp.toString());
        
        System.out.println("-- tmp (with padding) -- ");
        System.out.println(tmp.length());
        System.out.println(tmp.toString(2));

        System.out.println("-- records (no pad) -- ");
        System.out.println(records.length());
        System.out.println(records.toString());
        
        System.out.println("-- records (with padding) -- ");
        System.out.println(records.length());
        System.out.println(records.toString(2));
        
        System.out.println("-- activities -- ");
        System.out.println("-- activities (no pad) -- ");
        System.out.println(activities.length());
        System.out.println(activities.toString());
        
        System.out.println("-- activities (with padding) -- ");
        System.out.println(activities.length());
        System.out.println(activities.toString(2));

Output:

-- tmp (no pad) -- 
2
[{"id": "20"},{"id": "30"}]
-- tmp (with padding) -- 
2
[
  {
    "id":"20"
  },
  {
    "id":"30"
  }
]
-- records (no pad) -- 
1
[{"id": "20"}]
-- records (with padding) -- 
1
[
  {
    "id":"20"
  },
  {
    "id":"30"
  }
]
-- activities -- 
-- activities (no pad) -- 
1
[{"id": "30"}]
-- activities (with padding) -- 
1
[
  {
    "id":"30"
  }
]

The output for the records (with padding) is wrong: length = 1 is correct but extra entry added when padded !?

-- records (with padding) -- 
1
[
  {
    "id":"20"
  },
  {
    "id":"30"
  }
]

Any ideas ho to solve ?

SGE66 avatar Apr 02 '22 13:04 SGE66