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

WIP JSON serialization #101

Closed
wants to merge 1 commit into from
Closed

Conversation

mfine
Copy link
Contributor

@mfine mfine commented Apr 14, 2015

Playing around with JSON serialization. This is pretty broken and not working:

  • the parent objects are getting lost or not able to be serialized (e.g., payload); what really needs to happen is that the json dict from the parent needs to be merged in with the child's json dict. Or some such.
  • the from_json approach here is no bueno with nested structures - json.loads returns dicts and lists, while the existing objects are built up from construct into containers. Need some kind of json-to-construct mapping function.

Thoughts and ideas on how to do a better job here very welcome!

DO NOT MERGE

/cc @mookerji

@swiftnav-jenkins
Copy link
Contributor

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
http://zazu.ci.swiftnav.com/job/libsbp_Pull_Requests/6/
Test PASSed.

@mfine
Copy link
Contributor Author

mfine commented Apr 14, 2015

Another idea here would be to jettison the parent fields (filter them all out on the way out) and just compose the object from its own relevant fields. Still would have the issue with building containers for nested structures.

@mfine
Copy link
Contributor Author

mfine commented Apr 14, 2015

Just checked that this serializes ok - downside is that it won't serialize any of the parents stuff, or deserialize it back. Plus, the issue with the containers for nested objects is still there.

@@ -144,6 +145,19 @@ class ((( m.identifier | classnameify )))(SBP):
c = Container(**exclude_fields(self))
self.payload = ((( m.identifier | classnameify )))._parser.build(c)
return self.pack()

def to_json(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the __dict__, this doesn't get the parent objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does (I had filtered them originally with exclude_fields).

@mfine
Copy link
Contributor Author

mfine commented Apr 14, 2015

Replaced by #103.

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.

3 participants