Automatic deriving of instances for Json 51/2651/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 14 Feb 2019 12:45:23 +0000 (14:45 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 14 Feb 2019 12:45:23 +0000 (14:45 +0200)
commit22b86b38b00d6e168a5872e70113efd5fc1d81b6
tree863f9148d4bfd6dca32614554359167d5234d8ca
parent66b0fd2ee69d84d3107f109679b6fd1866f8f3fc
Automatic deriving of instances for Json

Example:

data GeographicalLocation = GeographicalLocation {
    latitude :: Double,
    longitude :: Maybe Double
}

deriving instance Json GeographicalLocation

testIt :: <Proc> ()
testIt = do
    print $ toJsonString GeographicalLocation {
        latitude = 1,
        longitude = Just 2 }
    print (fromJsonString
        "{ \"latitude\": 1, \"longitude\": 2 }"
        :: GeographicalLocation)
    print $ toJsonString GeographicalLocation {
        latitude = 1,
        longitude = Nothing }
    print (fromJsonString
        "{ \"latitude\": 1 }"
        :: GeographicalLocation)

#256

Change-Id: I7f44b65472436779045e4d15871858d14132dff9
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/Names.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/deriving/InstanceDerivers.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/deriving/JsonDeriver.java [new file with mode: 0644]
bundles/org.simantics.scl.data/scl/Data/Json.scl