nodes-ios / serpent Goto Github PK
View Code? Open in Web Editor NEWA protocol to serialize Swift structs and classes for encoding and decoding.
Home Page: https://nodes-ios.github.io/Serpent/
License: MIT License
A protocol to serialize Swift structs and classes for encoding and decoding.
Home Page: https://nodes-ios.github.io/Serpent/
License: MIT License
Hi,
Im using Serpent to save a Struct as JSON, when I try to convert the JSON back to the struct I get this error:
"Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.
Im using this to get the JSON:
let json = myStruct.encodableRepresentation()
And I'm using this to Convert the JSON back to a struct:
let jsonData = NSKeyedArchiver.archivedData(withRootObject: json) let dictionary = try! JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) as? NSDictionary
Where am I going wrong??
I'll do this.
The basic idea is that on the model level, you can mark one or more properties to be required so if in the incoming raw response they are not present stop the decoding and return empty struct/dictionary.
Serpent is still using the old comment style, which is no longer recommended by Apple, so we should switch to the new standard (///
on each line).
There's also some indentation issues in the project, which should be fixed. (maybe we could implement SwiftLint?)
Right now the Alamofire Extension uses a serializer that we hardcoded to only work with JSON. If we can provide a custom serializer (or even just a custom ResponseSerializerType
) then we can easily support XML or anything we want. As it is now, we have to copy-paste a lot of code into custom extensions to support XML
As seen here, we currently have no test coverage for the Alamofire extension.
We could utilise a library like OHHTTPSTubs to fake the network data and/or HTTPBin to get actual data.
Tests can fail due to endpoint failure or slow response time
Not really sure what's going on, as all builds pass in Travis, but when you build using Carthage, the non-iOS platforms fail (swift 2.3)
Serpent is not the fastest library out there, this needs to be fixed.
Currently has a Date
class, but would be nice to support NSDate
natively.
We should publish the documentation with GitHub pages. I can easily do that, I already tried it in my fork and it's looking good.
I ran Jazzy locally on Serpent, and it looks like the documentation percentage is not very high. This is about documentation for functions that the users don't actually access, but still, for completeness and quality, we should document those too.
When using Cashier the optional NSURL was not being decoded as NSRL even it was there before encoding after serialising from JSON.
This will force people to specify an unwrapper manually and prevent issues with a global "magic" unwrapper.
To imagine an example where this is problematic take Module A, where responseSerializable(completion)
is called with no unwrapper and expects to receive whatever was passed in. Then Module B changes the Parser.defaultUnwrapper
to something needed for itself. Module A does same action with the responseSerializable
and now fails because the Parser was changed without it's knowledge.
Only workaround this issue for now was to manully specify the unwrapper everywhere, which in turn eliminates the need for the global unwrapper in the first place. This is a great example of why you should not use a global variable.
Also check other frameworks for non-final classes
Update the badges and Requirements when applicable
CocoaPods still sees Serpent as 1.0.1, because we haven't updated the podspec since.
Will get back to this in a bit, leaving it as a reminder
Serializable saves it as a NSURL when encoding, resulting in the parser not parsing it correctly when deserialising from disk (Looks like it enters the mapped overload for StringInitializable and fails when it gets out a NSURL instead of a String)
All Serializable related performance tests should be merged into develop and master.
Tests for comparing other frameworks against Serializable should be moved to a different repository, so that this one isn't cluttered.
This will also make sure that performance tests are run in each travis build, which should make it easier for us to spot regressions or improvements.
I'm not sure if we're ready to break everyone's cartfiles yet, but we should coordinate across the other frameworks as well.
The master/dev branches do not have any features that swift-3.0 doesn't; the most recent commits to those are just updating to swift 2.3 and fixing travis. swift-3.0 has newer fixes and updates.
Currently, we do not support Linux but it would not require many changes to do so and might be a vital addition to help us when doing server side Swift and also to keep up with the competition.
Things that need to be changed to support Linux:
setValue
function available on LinuxThere are some bad APIs that return 200, but in the response JSON they return a status code that indicates an error.
It would be nice to have a way of manually checking for that and go to failure if necessary. In the example above, if ReturnCode is different than 0, the Failure case would be called and not the Success one (in the current implementation, it goes to Success).
Maybe returning nil in the Unwrapper should make it go to Failure instead of Success with the empty model.
Need to update the README with our v2.0 changes.
Looks like some old test models aren't using the <== operator.
This will hopefully make the framework name more unique and won't be as confusing.
.codebeatignore
should contain test folders and non-relevant code paths as documented here.
Serializable is seen as a mainly Objective-C repo.
Renaming the Prebuild folder to Dependencies should make it be ignored when analysing language, according to https://github.com/github/linguist/blob/master/lib/linguist/vendor.yml
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.