-
Notifications
You must be signed in to change notification settings - Fork 594
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
formField fails if custom unmarshaller is in scope #541
Comments
Yeah sounds like a docs thing, thanks for reporting. |
I wonder if it is a bug. Defined marshaller should work only for |
Not sure sure if this is the same issue, but it looks very similar. When using circe + akka-http-json support for JSON (which I believe provides generic unmarshallers to the scope) as in:
If I run and test the second route: I get the following error: But if I remove the JSON support it works correctly. Full issue on akka-http-json, but it might be actually an Akka HTTP issue. |
Yes, it's an anti-pattern to bring generic implicits into scope that are able to marshal/unmarshal everything. When you think about it, it is somewhat obvious that this cannot work. So, the recommendation is to never provide something like
where |
I think we can still improve the situation for |
…rm]` in FieldMagnets The reasoning is that probably all cases that implicit will be the same. Previous code allowed that implicit to be customized by users to use `formField` with other payloads than `multipart/formdata` and `application/x-www-form-urlencoded`. This isn't really useful and makes `formField` proner to implicit resolution problems. The old implicit are kept for now to keep binary compatibility but can be removed later.
…`FSFFU[String]`
…rm]` in FieldMagnets The reasoning is that probably all cases that implicit will be the same. Previous code allowed that implicit to be customized by users to use `formField` with other payloads than `multipart/formdata` and `application/x-www-form-urlencoded`. This isn't really useful and makes `formField` proner to implicit resolution problems. The old implicit are kept for now to keep binary compatibility but can be removed later.
…`FSFFU[String]`
…rshalling Simplify formField implicits a bit #541
is is not clear to me how we can add an unmarshaller for type T then? to add support for another content type without disabling existing content types? |
The original ticket was about a generic unmarshaller. You cannot bring an unmarshaller into scope that claims to unmarshal everything, this will conflict with other unmarshallers. And yes, to some degree the typeclass pattern cannot solve the case where you have several different unmarshallers in scope for a single concrete type. The implicit / typeclass pattern must use static information to figure out a single instance. That said, if you want to support multiple content types for a single concrete target type, you can create a composite Unmarshaller that supports all those content types using |
formField
directive fails if there is too generic unmarshaller in scope, that preventsFieldMagnet
machinery to work.It can happen quite a lot - for example when using akka-http-json4s or other generic unmarshaller.
Reproducer https://github.com/marekzebrowski/akka-http-form-field-bug
If it is not solvable, maybe a word of warning in documentation, or a guide how to write own unmarshaller would be helpful
The text was updated successfully, but these errors were encountered: