refit icon indicating copy to clipboard operation
refit copied to clipboard

Upgraded from 4.6.58 to 5.2.4 and Custom UrlParameterFormatter no longer handles lists the same way

Open gdodd1977 opened this issue 3 years ago • 2 comments

As the title suggests, I updated my version and then had to update my custom url parameter formatter for the new override format.

Old version:

public class LocationDeviceDataUrlParameterFormatter : DefaultUrlParameterFormatter
    {
        public override string Format(object parameterValue, ParameterInfo parameterInfo)
        {
            if (parameterValue == null)
                return null;

            if (parameterValue is LocationDeviceData locationDeviceData)
            {
                return JsonConvert.SerializeObject(locationDeviceData);
            }

            return base.Format(parameterValue, parameterInfo);
        }
    }

New Version:

public class LocationDeviceDataUrlParameterFormatter : DefaultUrlParameterFormatter
    {
        public override string Format(object parameterValue, ICustomAttributeProvider attributeProvider, Type type)
        {
            switch (parameterValue)
            {
                case null:
                    return null;
                case LocationDeviceData locationDeviceData:
                    return JsonConvert.SerializeObject(locationDeviceData);
                default:
                    return base.Format(parameterValue, attributeProvider, type);
            }
        }
    }

With the old version my query string would contain "LocationDeviceData={"name":"something1", "value":"1"}&LocationDeviceData={"name":"something2","value":"2"}". Now with the new version the query string is "LocationDeviceData={"name":"something1", "value":"1"}.{"name":"something2","value":"2"}"

The issue is that this is going to cause issues for the api that I'm calling with this since it's expecting it the old way. Is there any way to control how it generates the request string for a list in 5.2.4?

gdodd1977 avatar Sep 14 '21 16:09 gdodd1977

This looks like a bug. That said, what is the behavior you're seeing in v6? The 5.x series is old.

clairernovotny avatar Sep 27 '21 11:09 clairernovotny

@gdodd1977 Try setting RefitSettings.CollectionFormat to CollectionFormat.Multi. Between 4 and 5 the behavior of non-top-level collections was changed to respect the collection format setting (defaulting to CSV). If that doesn't work, it would help to see the method declaration for the endpoint that references this parameter.

kmcclellan avatar Jan 07 '22 15:01 kmcclellan