Skip to content
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

[fuel-jackson] Add Request.body(any: Any) extension method #662

Closed
david-wg2 opened this issue Jul 17, 2019 · 18 comments · Fixed by #728
Closed

[fuel-jackson] Add Request.body(any: Any) extension method #662

david-wg2 opened this issue Jul 17, 2019 · 18 comments · Fixed by #728

Comments

@david-wg2
Copy link

I'd like to be able to make requests like this:

 val (request, response, result) = Fuel.post(url)
            .body(MyCustomRequestBodyObject(...)) // here
            .responseObject<MyCustomResponseBodyObject>()

Currently I have an extension method in my project which allows this:

fun Request.body(any: Any) = body(mapper...)

Would be nice if this was a part of the fuel-jackson module.

@SleeplessByte
Copy link
Collaborator

I don't think I quite understand what you're asking for 😅. I personally think it's great to add project-based extension methods in your project!

@tipsy
Copy link

tipsy commented Jul 17, 2019

I don't think I quite understand what you're asking for 😅. I personally think it's great to add project-based extension methods in your project!

The kotlin-jackson module adds responseObject() as an extension-function, so you can easily convert a HTTP response body to a Kotlin object.

I'm proposing adding another extension-function, body(), so you can easily convert a Kotlin object to a request body.

@SleeplessByte
Copy link
Collaborator

Got it. Can you post the extension method in full that you currently use? I think we can add this to all the libraries, if applicable!

@tipsy
Copy link

tipsy commented Jul 17, 2019

I can do that tomorrow. It's just the standard serialization call though, nothing out of the ordinary.

It will work fine with all libraries.

@tipsy
Copy link

tipsy commented Jul 18, 2019

fun Request.body(any: Any) = body(defaultMapper.writeValueAsString(any)) 

@SleeplessByte
Copy link
Collaborator

Thanks. We'll probably have to do something like:

fun Request.body(data: Any, mapper = defaultMapper) = body(mapper.writeValueAsString(data)) 

@tipsy
Copy link

tipsy commented Jul 18, 2019

That'd be great.

@benjefferies
Copy link

I'm switching from fuel-gson to fuel-jackson and this is a missing feature where gson has a jsonBody extension

@SleeplessByte
Copy link
Collaborator

@benjefferies yes, I feel like adding jsonBody or body everywhere is cewl :)

@kittinunf
Copy link
Owner

@tipsy are you happy to throw a quick PR? I would love to see it added ❤️

@tipsy
Copy link

tipsy commented Jul 21, 2019

I tried to clone the project and run it locally, but got an SDK location not found. error. I have some other stuff I have to deal with today, so I can't really spend too much on this.

@iNoles
Copy link
Collaborator

iNoles commented Jul 21, 2019

I tried to clone the project and run it locally, but got an SDK location not found. error. I have some other stuff I have to deal with today, so I can't really spend too much on this.

Ah it is looking to Android SDK path.

@tipsy
Copy link

tipsy commented Jul 21, 2019

Ah it is looking to Android SDK path.

Why? How is this project related to Android?

@SleeplessByte
Copy link
Collaborator

Ah it is looking to Android SDK path.

Why? How is this project related to Android?

fuel-android is

@tipsy
Copy link

tipsy commented Jul 21, 2019

fuel-android is

I see. Is Android Studio required to run the project?

@SleeplessByte
Copy link
Collaborator

No, @kittinunf and I both run IntelliJ (NO Android Studio).

@panpanini
Copy link

I can take a look at this if people are busy 🙋

@lucasqueiroz
Copy link
Collaborator

Is there any updates on this issue?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants