-
Notifications
You must be signed in to change notification settings - Fork 62
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
JSON array to String #79
Comments
Do you have a specific reason for wanting to extend Marshal in this case? Could you just do something like this? let strings: [String] = try json.value(for: "somekey")
let joinedString = strings.joined(separator: ",") |
Thanks! This will do as shortcut. The reason I wanted to extend it is to automate generation of the
(jsonKeys maps from coredata attributes to whatever is coming from JSON). I am using custom mogenerator templates for this and it would be pretty unwieldy pretty soon if I start adding this:
as exceptions. I can do post-generation changes like above, only need to remember doing them each time model classes are regenerated. Not a big issue for this particular model, but would like a cleaner solution. I also auto-generate |
You might consider then writing reusable functions for transforming to CSV and back. I think the difficulty here is how do you extend the behavior to provide this behavior for only a subset of We have been discussing adding an optional transform function to the API in #73. This could help with this as well since you could do something like: let csv = try json.value(for: "somekey" transform: arrayToCSV) where When marshaling, you'd still just write a |
Thanks, the transform approach sounds really good. I'll keep my eye on the #73 then |
How can Marshal be extended to allow converting a JSON like this:
"somekey": ["s1", "s2", "s3"]
into this
"s1,s2,s3"
I had few multiple false starts already, can't figure it out.
The text was updated successfully, but these errors were encountered: