Giter Site home page Giter Site logo

nodes-ios / serpent Goto Github PK

View Code? Open in Web Editor NEW
285.0 15.0 15.0 3.24 MB

A protocol to serialize Swift structs and classes for encoding and decoding.

Home Page: https://nodes-ios.github.io/Serpent/

License: MIT License

Swift 100.00%
swift parsing mapper json alamofire decoding cocoapods model-boiler encoding carthage

serpent's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

serpent's Issues

JSONSerialization Error

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??

Feature request to mark properties as required

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.

New comment style, indentation issues

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?)

Provide a way to override the default `serializer`

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

Readme update

  • mention that it was previously known as Serializable
  • update the requirements to mention macOS/tvOS/watchOS
  • update the code examples in the README to be Swift 3
  • maybe mention older versions support in requirements (like in Installation - Carthage)

Improve code documentation

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.

Encoding optional NSURL

When using Cashier the optional NSURL was not being decoded as NSRL even it was there before encoding after serialising from JSON.

Remove static defaultUnwrapper on Parser

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.

Update podspec

CocoaPods still sees Serpent as 1.0.1, because we haven't updated the podspec since.

Fix travis

Will get back to this in a bit, leaving it as a reminder

Merge performance tests, move comparison tests to separate repository

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.

One final master/dev tag and make swift-3.0 new master

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.

Linux support

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:

  • get rid of Bridging Box on Linux
  • get rid of UIKit related extensions (UIColor)
  • make NSDictionary's setValue function available on Linux
  • make tests compile and run on Linux properly

Allow the developer to fail the request in implementation even if it returned 200

There are some bad APIs that return 200, but in the response JSON they return a status code that indicates an error.

image

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.

Rename to Serpent

This will hopefully make the framework name more unique and won't be as confusing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.