ngiachou / WalletHero

A hero we all deserve. Tracking your monthly costs was never been so much fun.
GNU General Public License v3.0
0 stars 0 forks source link

Implement a JSON serialization of PersonalBank #9

Closed ngiachou closed 5 years ago

ngiachou commented 5 years ago

We need a way of saving in a file the object of PersonalBank. A way of doing that is by using the JSON format (example).

Achieving that is not obvious since the default encoder of Python's json module is not able to serialize that kind of objects. Therefore, the default encoder must be extended as stated in the official documentation for the json module here.

Bellow follows an example of a PersonalBank object JSON serialization:

{
    "balance": 500,
    "history": [
        {
            "product list": [
                {
                    "name": "Beer",
                    "price": 2.5
                },
                {
                    "name": "Pizza",
                    "price": 7.9
                }
            ],
            "environment characteristic": "friends",
            "place": "in",
            "date": "2018-10-03"
        },
        {
            "product list": [
                {
                    "name": "Beer",
                    "price": 1.5
                },
                {
                    "name": "Pizza",
                    "price": 1.0
                },
                {
                    "name": "Cigarettes",
                    "price": 4.0
                }
            ],
            "environment characteristic": "friends",
            "place": "out",
            "date": "2018-10-09"
        }
    ]
}