Open danielgomezrico opened 2 years ago
👀
Sorry, just dropped out of life a bit. Will have a look later.
@danielgomezrico is this still an issue?
@techouse yeah
@danielgomezrico Getting to the bottom of this slowly.
From some initial tests I've written, the support for these built_value
serializers only extends to encoding and decoding the payload, not the query params, as per definition
/// An interface for implementing request and response converters.
///
/// [Converter]s convert objects to and from their representation in HTTP.
///
/// [convertRequest] is called before [RequestInterceptor]s
/// and [convertResponse] is called just after the HTTP response,
/// before [ResponseInterceptor]s.
///
/// See [JsonConverter] and [FormUrlEncodedConverter] for example implementations.
@immutable
abstract class Converter {
/// Converts the received [Request] to a [Request] which has a body with the
/// HTTP representation of the original body.
FutureOr<Request> convertRequest(Request request);
/// Converts the received [Response] to a [Response] which has a body of the
/// type [BodyType].
///
/// `BodyType` is the expected type of the resulting `Response`'s body
/// \(e.g., `String` or `CustomObject)`.
///
/// If `BodyType` is a `List` or a `BuiltList`, `InnerType` is the type of the
/// generic parameter (e.g., `convertResponse<List<CustomObject>, CustomObject>(response)` ).
FutureOr<Response<BodyType>> convertResponse<BodyType, InnerType>(
Response response,
);
}
To encode this in the Query will require quite some work.
I am missing this too. What is even worse is that I can not write my own converter to handle query params as I need. Request converter will be only applied when body is not empty.
I am missing this too. What is even worse is that I can not write my own converter to handle query params as I need.
@radzish you can always submit a PR 🤗
Ran into this problem with regular enums. One way to work around this is to write custom toString() method:
@override
String toString() {
return this.name;
}
@dustin-graham yep, that's how I always work with it.
I'll take another look at this over the Xmas holidays unless someone beats me to it 🤞
Not sure if this resolves this particular custom serialization issue, but last week I replaced the old query serialization with my own port of qs in https://github.com/lejard-h/chopper/pull/592.
qs has the ability to use custom Encoders, however, that's not exposed in Chopper. Have a play with it and see if it works for your particular built_value
issue, otherwise do as suggested above and always add a toString()
method.
CC / @dustin-graham @radzish @danielgomezrico
Current
I use BuiltValue with EnumClass to have nice enums, but Im trying to use an enum as a
@Query
param and it uses thetoString
value in the request instead of using the serializer value.I have an Enum that is declared like:
The generated serializer:
And my service like this:
But when I see how the request is done, it sends
faceToFace
(visitType.toString()
value) instead of the serializerTurnVisitType.serializer
and thewiredValue
and sendface_to_face
.Some places on chopper
It does use
toString
on every query param, and it does not try to use the serializes.Here: https://github.com/lejard-h/chopper/blob/f558bc7aabc36e819611cc7001d8f37f59dae309/chopper/lib/src/request.dart#L126
Here: https://github.com/lejard-h/chopper/blob/82b951fe278fcd783de5285b4ef2b7cbbede61c9/chopper/lib/src/utils.dart#L76-L82
Expected
The url is built using the serializer if the type have it declared, and