Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

original decoder uses Json.Decode.Pipeline without importing it #28

Open
teodorlu opened this issue Jun 9, 2017 · 1 comment
Open

Comments

@teodorlu
Copy link

teodorlu commented Jun 9, 2017

Thanks for a great service!

This JSON gives some funny results.

Test case

{"cpus":4
   ,"port":8080
   ,"localprefix":"localfolder"
   ,"name":"myjob"
   ,"hash":"edebf0f9966282ea565cf6e3b0cf1eff"
   ,"source-folder":"myfolder"
   ,"load-timestamp":1496932552590
}

Generated Elm code (as of 2017-06-09 from http://eeue56.github.io/json-to-elm/, toplevel alias "Job"):

import Json.Encode
import Json.Decode exposing (field)

type alias Job =
    { cpus : Int
    , port : Int
    , localprefix : String
    , name : String
    , hash : String
    , sourceFolder : String
    , loadTimestamp : Int
    }

decodeJob : Json.Decode.Decoder Job
decodeJob =
    Json.Decode.Pipeline.decode Job
        |> Json.Decode.Pipeline.required "cpus" (Json.Decode.int)
        |> Json.Decode.Pipeline.required "port" (Json.Decode.int)
        |> Json.Decode.Pipeline.required "localprefix" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "name" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "hash" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "sourceFolder" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "loadTimestamp" (Json.Decode.int)

encodeJob : Job -> Json.Encode.Value
encodeJob record =
    Json.Encode.object
        [ ("cpus",  Json.Encode.int <| record.cpus)
        , ("port",  Json.Encode.int <| record.port)
        , ("localprefix",  Json.Encode.string <| record.localprefix)
        , ("name",  Json.Encode.string <| record.name)
        , ("hash",  Json.Encode.string <| record.hash)
        , ("sourceFolder",  Json.Encode.string <| record.sourceFolder)
        , ("loadTimestamp",  Json.Encode.int <| record.loadTimestamp)
        ]

Unexpected things

  1. The decoder uses Json.Decode.Pipeline without importing it
  2. The decoder uses a pipeline even if the setting says original

Walkaround

After adding import Json.Decode.Pipeline to the top of the file and running elm package install NoRedInk/elm-decode-pipeline, code compiles.

@holgerl
Copy link

holgerl commented Apr 10, 2019

This was a problem for me too. It should not use pipeline when the original setting is active!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants