Populating JSON array requires direct store manipulation

Bug #928710 reported by Chris Hillery
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zorba
Fix Released
Medium
Markos Zaharioudakis

Bug Description

New bug description:
The only way to create a JSON array item with members is to first create the item, then populate it by manipulating the store using Store::populateJSONArray(). This seems like a bad API as only update primitives should be actually manipulating the store. (The way you create a JSON object with pairs is similar - you create the JSONObject item first, then "copy" pairs into it. This "copy" method also seems problematic as it can be done at any time, and really should only be used by update primitives.)

Original bug description:
If you are creating JSON items via the store API, the only way to add members to an array is to use the "no-copy copy()" trick, calling copy() on the member Item and passing a store::CopyMode with theDoCopy set to false.

However, copy() is not implemented for Items of atomic types (at least integer and string), so there is no way at all to create a JSON array with strings or integers as members. This of course means there's no way to do it with the public C++ API either.

Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

The way to do this is to first create an empty array, and then use the zorba::store::Store::populateJSONArray() method.

Changed in zorba:
assignee: Markos Zaharioudakis (markos-za) → Chris Hillery (ceejatec)
Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

Maybe it's the right solution to have this function but I'm not totally convinced. We have been going into the direction of not having updating functions in the store api. IMHO, this function should make it into the item factory and only be used to initially create an item. What do you think?

Chris Hillery (ceejatec)
Changed in zorba:
importance: Critical → Medium
milestone: 2.2 → none
assignee: Chris Hillery (ceejatec) → Markos Zaharioudakis (markos-za)
summary: - No way to populate JSON array with atomic values via store API
+ Populating JSON array requires direct store manipulation
Revision history for this message
Chris Hillery (ceejatec) wrote :

The public ItemFactory works as Matthias suggests: It accepts a vector<Item> of members to put into the array. After creation, it is not possible to modify JSON objects or arrays via the public API.

I have changed the implementation of ItemFactory::createJSONArray() to use Store::populateJSONArray() and it works, so the urgency behind the original bug report is gone (thanks!). I've re-purposed this bug to track the issue Matthias raised; see the new bug description.

description: updated
Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

The Store::populateJSONArray() method has been removed. Look at the new ItemFactory methods for creating JSON items.

Changed in zorba:
status: New → Fix Committed
Changed in zorba:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.