Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for duplicate fieldnames in dom.Value#Struct #679

Merged
merged 7 commits into from
Mar 1, 2021

Conversation

desaikd
Copy link
Contributor

@desaikd desaikd commented Feb 10, 2021

Description of changes:
This PR is to support duplicate fields in a Struct according to the Ion Spec.

Tasks:

  1. Added changes in the dom.Value#Struct for supporting duplicate fields. (All the Struct field will now be stored in (fieldname, values) -> [string, Value[]] form)
  2. dom.Value#Struct constructor would accept both Iterable<string, Value> as well as Iterable<string, Value[]> for creating Struct.
  3. Added getAll and allFields methods for getting all values of Struct fields.
  4. toString method returns with all the values of Struct fields.
  5. Changes in test suite for duplicate fields.
  6. add tests for duplicate fields.

src/dom/Null.ts Outdated Show resolved Hide resolved
test/dom/equivalence.ts Outdated Show resolved Hide resolved
test/dom/equivalence.ts Show resolved Hide resolved
test/dom/dom.ts Show resolved Hide resolved
@desaikd
Copy link
Contributor Author

desaikd commented Feb 16, 2021

Completed Tasks:

  1. added changes for getAll() and allFields() methods.
  2. changed ionEquals() method for checking unordered duplicate fields.
  3. Tests suite changes for all the above tasks.

Questions:
Could you explain with an example on how the fields return value would look like? Also for the iterator?
e.g.

{foo: 1, baz: true, foo: 2} 

For above Struct value what should be the return value for fields() as well as iterator ?
Currently it will return something like this:

[['foo',[1,2]] , ['baz' , true]]

@desaikd
Copy link
Contributor Author

desaikd commented Feb 17, 2021

Changes:

{foo: 1, baz: true, foo: 2} 

fields() would return Struct fields as below with only the last value:

[['foo', 2] , ['baz' , true]]
  • To get all the field values allFields() can be used.
  • toString method returns with all the values of Struct fields.

src/dom/Struct.ts Outdated Show resolved Hide resolved
src/dom/Value.ts Outdated Show resolved Hide resolved
src/dom/Value.ts Outdated Show resolved Hide resolved
@desaikd desaikd merged commit 81b62ce into amazon-ion:master Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants