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

Support For Matrix Param In Retrofit #2898

Open
ankurpathak opened this issue Sep 20, 2018 · 4 comments
Open

Support For Matrix Param In Retrofit #2898

ankurpathak opened this issue Sep 20, 2018 · 4 comments
Labels

Comments

@ankurpathak
Copy link

@ankurpathak ankurpathak commented Sep 20, 2018

Both Java Server Side framework for Rest Web Services Spring MVC and Jax Rs have support for Matrix Param.
Retrofit is the poular java and android client for Rest Web Services and don't have support for matrix param. Sound's strange.
Here are the url from java docs of Jax Rs and Spring MVC:
https://docs.oracle.com/javaee/7/api/javax/ws/rs/MatrixParam.html
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/MatrixVariable.html

Here is a url to Spring MVC example explaning Matrix param:
https://www.baeldung.com/spring-mvc-matrix-variables

Here is lik to RFC standard explaning matrix variable:
https://tools.ietf.org/html/rfc3986#section-3.3

So please add support for Matrix Variable in Retrofit.

@JakeWharton
Copy link
Member

@JakeWharton JakeWharton commented Sep 20, 2018

That RFC does not define anything about these so-called "matrix" path parameters. It merely states that you may use those characters to delimit sub-segments inside of a single path segment. The link you supply which states the RFC defines anything about path parameters is inaccurate.

However, this can already be accomplished by using your own annotation, a Map type, and a registered string converter which renders the object to a String using whatever mechanism and joining characters that you want.

Since it's not part of any official HTTP spec and you can build this into Retrofit using its existing extension mechanisms, I'm inclined not to do anything here.

@JakeWharton JakeWharton added the Feature label Sep 20, 2018
@JakeWharton
Copy link
Member

@JakeWharton JakeWharton commented Sep 20, 2018

I would welcome this as a sample, in fact.

@ankurpathak
Copy link
Author

@ankurpathak ankurpathak commented Sep 21, 2018

That RFC does not define anything about these so-called "matrix" path parameters. It merely states that you may use those characters to delimit sub-segments inside of a single path segment. The link you supply which states the RFC defines anything about path parameters is inaccurate.

However, this can already be accomplished by using your own annotation, a Map type, and a registered string converter which renders the object to a String using whatever mechanism and joining characters that you want.

Since it's not part of any official HTTP spec and you can build this into Retrofit using its existing extension mechanisms, I'm inclined not to do anything here.

Can you provide link to reference documentation which describe how to do it with custom annotation, map and a registered string converter. Or some similar case.

@JakeWharton
Copy link
Member

@JakeWharton JakeWharton commented Sep 21, 2018

The javadoc for @Path talks about how values are encoded by asking the Retrofit.stringConverter() method. The Type and an array of parameter Annotation instances are supplied to that method which are forwarded to every registered Converter.Factory's stringConverter method. From that method, if you can handle the type, you return a Converter that takes the object and converters it to a string however you choose.

We have a sample which uses a JSON serializer to convert a query param using this mechanism: https://github.com/square/retrofit/blob/00e82dfbe19fd1a9b725b134b70dafe6a0bde8f4/samples/src/main/java/com/example/retrofit/JsonQueryParameters.java

@JakeWharton JakeWharton added Documentation and removed Feature labels Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.