Problem with additional order info containing list

Hi!

I have a problem with adding a list to additional order info. I have a class QuestionForm

public class QuestionForm : Litium.ComponentModel.IReadOnly
{
    public List<Question> Questions { get; set; }

    public bool IsReadOnly => false;

    public void MakeReadOnly()
    {
    }

    public object MakeWritableClone()
    {
        return this;
    }
}

…containing a list of Question

public class Question
{
    public string Id { get; set; }
    public string QuestionText { get; set; }
    public string AnswerText { get; set; }
}

I create a dictionary like this

var additionalInfoDictionary = new Dictionary<string, object>() { { "QuestionForm", questionForm } };

…and it works fine when I call

await cartContext.AddOrUpdateAdditionalInfoAsync(additionalInfoDictionary);

…but later when I call

await cartContext.ConfirmOrderAsync();

…I will get an error from Litium

2023-02-15 17:25:37.0628 [App:01] ERROR Litium.Connect.Application.Payments.PaymentServiceImpl - Error during order placement, payment system id 771a352d-eada-4227-82ec-ddde3bdc66b2, Details:{...} 
System.ArgumentException: The value for the additional info key QuestionForm is a complex type that not implement Litium.ComponentModel.IReadOnly.
at Litium.Application.Sales.AdditionalInfoHelper.Map(IDictionary`2 current, Object data)
at Litium.Connect.Application.Payments.PaymentServiceImpl.<>c__DisplayClass43_0.<AddOrUpdateCustomerAndPaymentInfo>b__0(CartContextSession cartContext)
at Litium.Application.Sales.CartContextSessionServiceImpl.UpdateAsync(Guid systemId, Func`2 fnUpdateCartAsync, CancellationToken cancellationToken)...

Any ideas of how to fix this?

Litium version: 8.7.2

I think your question class has to implement IReadOnly also.

Ok, I changed to

public class Question : Litium.ComponentModel.IReadOnly
{
    public string Id { get; set; }
    public string QuestionText { get; set; }
    public string AnswerText { get; set; }

    public bool IsReadOnly => false;

    public void MakeReadOnly()
    {
    }

    public object MakeWritableClone()
    {
        return this;
    }
}

…but get the same error

System.ArgumentException: The value for the additional info key QuestionForm is a complex type that not implement Litium.ComponentModel.IReadOnly.

I think the list is the problem(?)

Yes it has to be an IList not a List.

Don’t do this is my initial reaction, it will be problem and what you are running into is that the object is sent as json to the payment app, the payment app is later returning this information to Litium but the type information is lost so it tries to create and store an JObject instead of your typed object.

It exists a similar bug (litium.com) for a simple type that is stored as int and it will be converted to long.

I’ve tried IList instead of List, doesn’t work.
I solved it by saving my object as json and serializing/deserializing myself.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.