]> gerrit.simantics Code Review - simantics/platform.git/commit
Automatic deriving of instances for Json 15/2715/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 14 Feb 2019 12:45:23 +0000 (14:45 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 26 Feb 2019 09:19:00 +0000 (11:19 +0200)
commitbb1b1256a8ac8b24cdfe6556ba8def9adae11624
tree1f3c74184ec3dc3563c80b244f4ee7f2d6d91f2e
parent68494955c9ee84aa894508b9f954ae16cfccce53
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