Comments (11)
A pull request would be welcome! I don't personally think it's out of scope, but we didn't want to be too opinionated about it yet.
Further parsing can be built as a composition out of the string
family of methods, for instance:
let formatter = ...
self.dateOfBirth = try json.string("some", "key", "path", ifNotFound: true).flatMap(formatter.dateFromString)
That obviously leaves something to be desired (error handling, for one). I envisioned a ValueTransformer<In, Out>
as a case-by-case alternative to everything needing to be JSONDecodable
.
from freddy.
I can open a PR for consideration. Any thoughts on special date formats we'd like to support? At a minimum, I think it'd be nice to support two common Ruby date formats ("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZ"
and "YYYY-MM-DD HH:mm:ss ZZZ"
)
from freddy.
I personally think magical support for a specific format would be more confusing than opt-in support, but I won't say we wouldn't consider it.
from freddy.
All the dates in our REST APIs conform to ISO8601. I feel like that's somewhat standard, but i wouldn't lose sleep if i had to pass in a format string to adopt it.
from freddy.
All the dates in our REST APIs conform to ISO8601. I feel like that's somewhat standard, but i wouldn't lose sleep if i had to pass in a format string to adopt it.
I would be sooooooo happy if I had that experience. Unfortunately we see all kinds of date formats in practice, including some that can't be parsed by NSDateFormatter
(e.g., search for "DateTime Wire Format" for .NET 4.5). Given that, I'm not sure even a format string is an ideal solution. :-/ This is where the desire for value transformers is coming from, FWIW.
from freddy.
We just came up with the need to turn http://example.com/foo.jpg
into an NSURL
-typed property on our model object, and would also like either this special-cased or some kind of value transformer as mentioned above.
from freddy.
For URLs, there isn't much transformation needed. Can you make NSURL
conform to JSONDecodable
in your project?
from freddy.
We can without too much trouble, sure. I have a side-question on doing that though: when turning NSURL
's failable initialiser into one that throws
we thought using Freddy.JSON.Error. ValueNotConvertible
would be the appropriate error but I wasn't sure what to give for the value
parameter?
from freddy.
That's up to you and how you're handling/reporting errors. I'd put in the string that failed to convert. You could also define your own error case that doesn't have an associated value.
from freddy.
@ratkins were you able to conform NSURL
to JSONDecodable
by using its failable initializer? I couldn't get it done myself.
from freddy.
Closing due to inactivity. Given the advent of Codable
, Freddy is in maintenance mode and only considering bug fixes at this time.
from freddy.
Related Issues (20)
- [Help] Mapping a single element when an array is expected HOT 2
- Are there plans to continue development? HOT 1
- Update documentation
- How to Serialize Optional Vars HOT 3
- need to expose accessor that takes path as an array instead of variadic parameter HOT 2
- Implementing decimal support HOT 1
- Expose toJSONSerializationValue HOT 2
- Type decoding should be safe? HOT 1
- Payload notification HOT 5
- Podspec update? HOT 2
- Swift4c fails to build Freddy on release mode HOT 1
- Enable code coverage setting only for Debug builds - Xcode 9 issue
- does not compile with Xcode 9 HOT 5
- JSONParser in swift 4 is extremely slow for big data HOT 3
- Push 3.0.3 release to cocoapods master repo HOT 4
- CocoaPods: Requesting version '~> 3.0.2' installs version 3.0.3 HOT 1
- JSONSerialization.makeJSON fails on Linux due to no toll-free bridging HOT 1
- JSONParser.swift uses deprecated API when compiled against Swift 4.1 HOT 4
- 3.0 using deprecated API HOT 1
- Use typealias JString with external constructor versus String HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freddy.