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

Use enum value name instead of index in json #51

Merged
merged 1 commit into from Mar 11, 2020
Merged

Conversation

@TortoiseWrath
Copy link
Member

TortoiseWrath commented Mar 10, 2020

  • Instead of toJson(), each MultaccItem implementation shall now
    implement toMap(). toJson() will be inherited from a new default
    implementation in the base class, which calls toMap() then adds the
    item type to the resulting map.
    This prevents each implementation from having to add
    '_t': EnumToString.parse(getType())
    in its toJson() method
  • The key 'type' has been replaced with '_t' in MultaccItem
    serialization to make the resulting json slightly smaller and allow us
    to use the name 'type' for implementation-specific data such as
    phone number type.
  • Instead of the enum index, the EnumToString class is now used when
    serializing MultaccItems. This will allow the type enum to be modified
    in the future without breaking existing data.
  • PhoneItem and EmailItem added to switch statement in
    MultaccItem.fromDB() so they can now be deserialized with this factory

New dependency: enum_to_string, which makes serialization and especially
deserialization of enums easier.

This change will render any old database values for items useless!!
Luckily, to my knowledge we don't have any of those.
Compare the old format:
{'type': 7, 'email': 'sdg@multacc.com'}
to the new:
{'email': 'sdg@multacc.com', '_t': 'Email'}

If for some reason we need to maintain backward compatibility with the old format we haven't used, this isn't too difficult to accomplish.

* Instead of toJson(), each MultaccItem implementation shall now
  implement toMap(). toJson() will be inherited from a new default
  implementation in the base class, which calls toMap() then adds the
  item type to the resulting map.
  This prevents each implementation from having to add
    '_t': EnumToString.parse(getType())
  in its toJson() method
* The key 'type' has been replaced with '_t' in MultaccItem
  serialization to make the resulting json slightly smaller and allow us
  to use the name 'type' for implementation-specific data such as
  phone number type.
* Instead of the enum index, the EnumToString class is now used when
  serializing MultaccItems. This will allow the type enum to be modified
  in the future without breaking existing data.
* PhoneItem and EmailItem added to switch statement in
  MultaccItem.fromDB() so they can now be deserialized with this factory

New dependency: enum_to_string, which makes serialization and especially
deserialization of enums easier.

This change will render any old database values for items useless!!
Luckily, to my knowledge we don't have any of those.
Compare the old format:
  {'type': 7, 'email': 'sdg@multacc.com'}
to the new:
  {'email': 'sdg@multacc.com', '_t': 'Email'}
@TortoiseWrath TortoiseWrath requested review from mayank99 and micah-white Mar 10, 2020
@TortoiseWrath TortoiseWrath added this to In progress in multacc via automation Mar 10, 2020
@TortoiseWrath TortoiseWrath added this to the sprint-2 milestone Mar 10, 2020
@mayank99 mayank99 merged commit c4b2bdd into master Mar 11, 2020
1 check passed
1 check passed
build
Details
multacc automation moved this from In progress to Done Mar 11, 2020
@mayank99 mayank99 deleted the enum-serialization branch Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
multacc
  
Done
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.