Skip to content

Tags: 2jt/purescript-foreign-generic

Tags

v11.0.0

Toggle v11.0.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Merge pull request paf31#61 from fsoikin/purescript-0.14

Migrate to PureScript 0.14

v10.0.0

Toggle v10.0.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Add Decode/Encode instances for Record, simplify module structure (pa…

…f31#53)

* Add Decode/Encode instances for Record

* Docs

* Simplify the module structure

* Update README

* Better backwards-compatibility

v9.0.0

Toggle v9.0.0's commit message
Update dependencies (paf31#51)

v8.1.0

Toggle v8.1.0's commit message
Add Encode and Decode instances to Identity (paf31#50)

v8.0.0

Toggle v8.0.0's commit message
Encode Nothing as null rather than undefined (paf31#49)

Previously, the Encode (Maybe a) instance was mapping Nothing to
undefined, which meant that Nothing fields in records would disappear
when stringifying:

    -- old behaviour
    newtype Foo = Foo { x :: Maybe Int }
    derive instance genericFoo :: Generic Foo _

    foo = Foo { x: Nothing }
    log (encodeJSON foo)
    -- {"tag":"Foo","contents":{}}

This commit changes the behaviour of the Encode (Maybe a) instance so
that Nothing is mapped to null rather than undefined. This means that
Nothing fields are present in the JSON, with a value of null:

    -- new behaviour
    log (encodeJSON foo)
    -- {"tag":"Foo","contents":{"x":null}}

Note that we remain lenient about decoding records with Maybe fields:
a field may be present and have a value of null, or it may be absent;
in both cases, the field is decoded as Nothing.

This change brings foreign-generic more into line with Aeson, as by
default Aeson will also encode Nothing fields as present with a value of
null (in fact, this is configurable in Aeson: there is a configuration
option `omitNothingFields` which, when turned on, means that
Nothing-valued fields will be omitted during JSON encoding.)

Maybe values which ended up inside arrays in the encoded JSON are
unaffected by this change; previously they were mapped to `null` anyway.

Maybe values at the top level of the encoded JSON, however, are
affected. In fact, encoding Maybe values at the top level could
previously lead to runtime errors:

    -- previously
    > encodeJSON (Nothing :: Maybe Int)
    ./purescript-foreign-generic/.psci_modules/node_modules/Data.Show/foreign.js:30
      var l = s.length;
                ^

    TypeError: Cannot read property 'length' of undefined

    -- now
    > encodeJSON (Nothing :: Maybe Int)
    "null"

v6.0.0

Toggle v6.0.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Add Unit instances (paf31#43)

* Add Unit instances

* Void instances, docs

* Add Maybe instances

v5.0.1

Toggle v5.0.1's commit message
Fix bug constructorTagTransform (paf31#41)

* Add failing test for constructorTagTransform

* Fix bug with some constructoTagTransform functions

v5.0.0

Toggle v5.0.0's commit message
Add fieldTransform to Options (paf31#32)

* Add fieldTransform to Options

* Add comment about fieldTransform

v4.3.0

Toggle v4.3.0's commit message
Encode/Decode instances for StrMap (paf31#28)

* Encode/Decode instances for StrMap

* Use readStrMap

* Remove redundant checks