elm-bridge icon indicating copy to clipboard operation
elm-bridge copied to clipboard

Issue with UTCTime to Posix

Open XtraKrispi opened this issue 3 years ago • 2 comments

It would appear that there are default alterations UTCTime that convert fields into Posix. That's great, but it doesn't seem to be followed through in the generated code.

For example, it will correctly rename the field, but it does not import Time and uses a decoder called jsonDecPosix (autogenerated naming). That decoder does not exist.

Is there another way around this issue? Is there something I'm missing? We are using servant-elm but I tried directly through elm-bridge and got the same results.

This is an example (ignore the silly naming) from the generated code:

type alias FweetDto  =
   { fwuser: FwuserDto
   , fwody: String
   , fwimestamp: Posix
   }

jsonDecFweetDto : Json.Decode.Decoder ( FweetDto )
jsonDecFweetDto =
   Json.Decode.succeed (\pfwuser pfwody pfwimestamp -> {fwuser = pfwuser, fwody = pfwody, fwimestamp = pfwimestamp})
   |> required "fwuser" (jsonDecFwuserDto)
   |> required "fwody" (Json.Decode.string)
   |> required "fwimestamp" (jsonDecPosix)```

XtraKrispi avatar Mar 28 '22 19:03 XtraKrispi

Sorry for the late answer! I will try to take a look during the weekend, but as I do not use Elm anymore, that is not high priority.

bartavelle avatar Apr 04 '22 12:04 bartavelle

I wrote a very quick patch (see #53). If that works for you, would that be OK to use elm-community/json-extra, or should I add the feature in json-helpers ?

bartavelle avatar May 08 '22 14:05 bartavelle