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

Issue with JSON datetime Serialization #230

Open
ikiril01 opened this issue Feb 25, 2015 · 1 comment
Open

Issue with JSON datetime Serialization #230

ikiril01 opened this issue Feb 25, 2015 · 1 comment

Comments

@ikiril01
Copy link
Member

Certain CybOX fields that use xs:dateTime as their base type will throw "not JSON serializable" errors when trying to serialize python-cybox objects parsed in from CybOX XML documents to JSON, due to their being marshaled into python datetime objects in the bindings. E.g., https://github.com/CybOXProject/python-cybox/blob/master/cybox/bindings/cybox_core.py#L915-921.

A likely solution would be to check for such objects in to_dict() of cybox.Entity and if found, cast them to a string before passing them into the dictionary. This is essentially what python-stix does in its to_dict() methods.

This can be replicated via:

from datetime import datetime
from cybox.core import Action

a = Action()
a.timestamp = datetime.now()

print a.to_json()

This is related to: MAECProject/python-maec#66 and MAECProject/python-maec@0d844b6

@gtback
Copy link
Contributor

gtback commented Feb 26, 2015

I don't know if we want to convert it to a string in to_dict or to_json. For DateTimeObjectPropertys, to_dict already returns a string (I don't know if that's ideal or not). If we want to leave it as a datetime in the dictionary representation, we can write a custom JSON Encoder for this, and use this in our to_json function.

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

No branches or pull requests

2 participants