Try our conversational search powered by Generative AI!

Enumerable type not in the response

Vote:
 

For a given enumerable property:

public virtual IList<string> QuestionsAndAnswers { get; set; }

when calling Content Delivery API:

/api/episerver/v3.0/content/5421?expand=*

All properties of the block are received except the `QuestionsAndAnswers`.

Using:
- EPiServer.CMS 12.15.1
- EPiServer.CMS.Core 12.11.0
- EPiServer.ContentDeliveryApi.Cms 3.6.0

How should I let the API return that list?

#296038
Feb 06, 2023 9:23
Vote:
 

I believe you need to create your own convertor see here for an example 

Property Lists Serialization and Content Delivery API (optimizely.com) 

#296039
Feb 06, 2023 11:04
Vote:
 

Thank you!

Basing on your post, I was able to figure out the solution for IEnumerable<string>:

public class ListPropertyConvertorProvider : IPropertyConverterProvider
{
private readonly IServiceProvider _serviceProvider;

public ListPropertyConvertorProvider(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
}

public IPropertyConverter? Resolve(PropertyData propertyData)
{
return propertyData switch
{
StringListProperty => _serviceProvider.GetRequiredService<StringItemListPropertyConverter>(),
_ => null
};
}

public int SortOrder => 100;
}

public class StringItemListPropertyConverter : IPropertyConverter
{
public IPropertyModel Convert(PropertyData propertyData, ConverterContext contentMappingContext)
{
return new StringItemPropertyModel((StringListProperty)propertyData);
}
}

public class StringItemPropertyModel : PropertyModel<IEnumerable<string>, PropertyList<string>>
{
public StringItemPropertyModel(StringListProperty type) : base(type) =>
Value = type.List;
}
#296048
Feb 06, 2023 13:16
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.