Skip to content

Serializing and Deserializing MarketBook to/from JSON loses market_definition #517

@vincentmele

Description

@vincentmele

I am trying to serialize and deserialize MarketBook objects. I am 1) going from MarketBook to JSON, then 2) JSON back to MarketBook. It appears that when converting JSON to MarketBook, the marketDefinition does not set itself. With a bit of trial and error, I discovered that I can get a correct MarketBook by setting the key "market_definition" instead of the "marketDefinition" in the JSON outputted from first step.

Assuming an existing, populated MarketBook object as "mb1"

Doesn't work, market_definition is not set:

import json
mb_json = mb1.json()
mb_dict = json.loads(mb_json)
new_mb = MarketBook(**mb_dict)
# new_mb.market_definition is None at this point.

Works, market_definition is set:

import json
mb_json = mb1.json()
mb_dict = json.loads(mb_json)
mb_dict['market_definition'] = mb_dict['marketDefinition']
new_mb = MarketBook(**mb_dict)
# new_mb.market_definition has correct output

If this isn't how I should be storing MarketBooks, I'd be more than happy to be corrected :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions