I’m trying to Encode a model that is using a dict attribute but I don’t know how to encode that parte of the model, I’m trying to do the following.
type alias TemplateResponses =
{ userId : String
, name : String
, testResponses : List TestResponse
}
type alias TestResponse =
{ name : String
, responses : List Response
}
type alias Response =
{ id : String
, response : Dict Int String
}
emptyTemplateResponse : TemplateResponses
emptyTemplateResponse =
{ userId = “234”
, name = “”
, testResponses = []
}
templateResponseEncoder : TemplateResponses -> Encode.Value
templateResponseEncoder templateResponse =
Encode.object
[ ( “userId”, Encode.string templateResponse.userId )
, ( “uid”, Encode.string templateResponse.name )
, ( “testResponses”, Encode.list testResponseEncoder templateResponse.testResponses )
]
testResponseEncoder : TestResponse -> Encode.Value
testResponseEncoder testResponse =
Encode.object
[ ( “name”, Encode.string testResponse.name )
, ( “responses”, Encode.list responseEncoder testResponse.responses )
]
responseEncoder : Response -> Encode.Value
responseEncoder response =
Encode.object
[ ( “id”, Encode.string response.id )
, ( “response”, Encode.dict response.response)
]
but i receive the next error
The 2nd element is a tuple of type:
( String, #(v -> Encode.Value) -> Dict k v -> Encode.Value# )
But all the previous elements in the list are:
( String, #Encode.Value# )