Skip to content

is_plain() in VocabString causes issues with to_dict()/from_dict() round trip #174

Closed

Description

@ikiril01

The use of the is_plain() in the to_dict() method in VocabString (https://github.com/CybOXProject/python-cybox/blob/master/cybox/common/vocabs.py#L65-66) means that the xsi:type of the vocabulary is typically not returned in the dictionary. Accordingly, subsequent calls to from_dict() on this output means that the xsi:type will be set to the default value of BAD_XSI_TYPE.

Honestly, I think we should consider getting rid of these is_plain() methods. While they do simplify the output a little, they also cause these round-trip headaches, as well as the expectation that consumers will have to parse two different data structures (strings and dictionaries) depending on the type of data contained within.

Activity

  1. bworrell commented on Jun 19, 2014

    @bworrell
    Contributor

    I ended up changing the behavior of is_plain() in python-stix so that the xsi_type key is almost always exported. Also, BAD_XSI_TYPE was removed so that plain VocabString instances could be exported.

    I am currently working on some other issues in VocabString here:https://github.com/STIXProject/python-stix/blob/vocabs/stix/common/vocabs.py

    I have been working on a local branch to port over some of these changes to python-cybox, though it hasn't been super easy due to the use of TypedField.

  2. bworrell commented on Jun 19, 2014

    @bworrell
    Contributor

    Here is the issue driving the python-stix/vocabs branch and change set: STIXProject/python-stix#145

  3. ikiril01 commented on Jun 19, 2014

    @ikiril01
    MemberAuthor

    Ah, interesting - thanks for the heads up on the approach you've taken in python-stix. I think always exporting the xsi_type key if it exists is a sensible approach, so we can likely make a similar change to the is_plain() method in python-cybox, at least as an interim solution.

  4. gtback commented on Jul 2, 2014

    @gtback
    Contributor

    I like keeping the "plain" string where possible and not exporting the xsi:type if it is the "standard" XSI type for that vocab. I'm not sure if it's something we can easily check, though.

  5. gtback commented on Jul 2, 2014

    @gtback
    Contributor

    On the other hand, I guess I'm OK if we never export the "plain" string (though it makes the JSON more verbose), as long as we support reading in both the plain and "full dictionary" forms of vocab strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions