tristanhimmelman / ObjectMapper

Simple JSON Object mapping written in Swift
MIT License
9.14k stars 1.03k forks source link

toJSONString() function not working #1078

Open vanitaladkat opened 4 years ago

vanitaladkat commented 4 years ago

Your JSON dictionary:

{
  "name": "ObjectMapper",
  "url": "https://github.com/Hearst-DD/ObjectMapper"
}

Your model:

class Repo: Mappable {
  var name: String!
  var url: URL!

  init(_ map: Map) {
    name <- map["name"]
    url <- map["url"]
  }
}

What you did:

let repo = Mapper<Repo>().map(myJSONDictionary)
var repos: [Repo] = []
repo.append(repo)
let json = repos.toJSOnString(). //need json string for array

What you expected:

I exepected something like:

json as:
"[{"name": "Objectmapper", "url": "http:github.com"}]"

What you got:

json is getting as:
[{}]
the model isnt conveting to dictionary returning blank dictionary.
yuvrajsinh-plackal commented 4 years ago

@vanitaladkat Have you got any solution?

vanitaladkat commented 4 years ago

@yuvrajsinh-plackal I was missing map function in my Model class. Adding mapping function with keys worked for me

yuvrajsinh-plackal commented 4 years ago

@vanitaladkat Thanks for that I also got my issue. I was using same key for two properties, so second use of key was overriding first one

mxnmike commented 4 years ago

I have the issue with Dates.... its just ignoring them.... have you face this before? and how did you fixed if you did?

thanks.