Skip to content
  • Laurent Bachelier's avatar
    json: Force Decimal as str with simplejson · 81b12994
    Laurent Bachelier authored and Romain Bignon's avatar Romain Bignon committed
    simplejson has an internal way of formatting Decimal so it bypasses our
    formatter.
    Since weboob often deals with money, floats are not a good idea.
    
    Previousl:
    Decimal('1.1') => 1.1 with simplejson+WeboobEncoder
    Decimal('1.1') => '1.1' with json+WeboobEncoder
    Now both give '1.1'.
    
    Under simplejson:
    Using dump(cls=...) always initialize the Encoder class with the
    use_decimal=True argument (unless the argument is provided in the dump
    function, but that requires a lot of alteration in Weboob, and I would
    rather remove simplejson support altogether). So when present, we force it.
    
    Under json:
    There is no use_decimal, so we already go to the default() method of the
    Encoder.
    81b12994