Add Unbox capability #1

Closed
VivienGiraud opened this Issue Nov 3, 2016 · 9 comments

Projects

None yet

2 participants

@VivienGiraud

Hi,

It would be pretty neat if you can add Unbox capability.
What do you think about that?

Regards,
Vivien

@ijoshsmith
Owner
ijoshsmith commented Nov 3, 2016 edited

Hi Vivien. Why would you want this tool to support generating Swift code that uses the Unbox API for working with JSON? That project's motto is "The easy to use Swift JSON decoder". But the point of json2swift is that you don't need to write any code at all to decode JSON: the tool writes it all for you.

Thanks,
Josh

@ijoshsmith
Owner

By the way, @VivienGiraud I am not dismissing your request for Unbox support. I really want to know if there is a legitimate reason for doing this, which I have not thought of.

Josh

@VivienGiraud

Hi @ijoshsmith,
I mean, you take json file like:

{  
  "name": "John",  
  "age": 27  
}

And get:

struct User {
  let name: String
  let age: Int
}

extension User: Unboxable {
    init(unboxer: Unboxer) throws {
        self.name = try unboxer.unbox(key: "name")
        self.age = try unboxer.unbox(key: "age")
    }
}

I might be wrong with the usage of your tool, in this case I'm sorry :/

Vivien

@ijoshsmith
Owner

@VivienGiraud I understood what you meant, but I do not know why you are asking for this. The purpose of libraries like Unbox is to make it easier/faster to write code that consumes JSON. Such libraries add value for developers who write code to consume JSON. When a developer uses json2swift there is no need to write such code. Therefore, there is no benefit (that I know of) in continuing to use libraries such as Unbox if you have a tool that generates all the JSON-consuming code that you need.

@ijoshsmith ijoshsmith closed this Nov 3, 2016
@VivienGiraud

Please correct me if I'm wrong, json2swift take a JSON file as input and will output the swift structure of this JSON file.
I was wondering, it would be great if I can do the same with json2swift, if I'm right with the usage, to create Unbox struct by giving a JSON file that come from Spotify or IMDB API for example.
When I want to connect to an API, it's pain in the ass to write all the Unbox things to consume JSON.

@ijoshsmith
Owner
ijoshsmith commented Nov 3, 2016 edited

Technically, yes it's possible to have json2swift generate Swift code that uses the Unbox API. I just don't see why to bother with continuing to use Unbox at all.

If JSON libraries, like Unbox, are a way to make yourself run faster; json2swift is an automobile.

@VivienGiraud

Hmmm, ok.
Unbox is an extra layer to decode JSON, json2swift serialise it without extra layer.
So if my previous sentence is correct, I understand how dumb my request is...

Sorry about the confusion.

@ijoshsmith
Owner

No problem, it's not a dumb request at all! Thinking in terms of code generation can take a little getting used to. Thank you for taking an interest in my project and bringing this up.

@VivienGiraud

Anyway, I'm was looking for something like that since some weeks.
Definitely worth a try when I have some part time.
All the best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment