Skip to content

[bug]: search fails to deserialize in csharp client after merging #3869 #3934

@Kalmar99

Description

@Kalmar99

Description

in #3869 we added a new field to the RenderingContent model, however it contained some typos in the syntax causing the banners to not be treated like a list.

Response from api:

"widgets": {
   "banners": [
    {
     "image": {
      "urls": [
       {
        "url": "https://komplett.no/marketingmedia/155541/k_wo_q324_macbookstudents_stripe.jpg"
       }
      ],
      "title": "text"
     },
     "link": {
      "url": "https://www.komplett.no/kampanje/40375/test"
     }
    }
   ]
  }

However the model that is genered in the csharp client looks like this:

//
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
//
using System;
using System.Text;
using System.Linq;
using System.Text.Json.Serialization;
using System.Collections.Generic;
using Algolia.Search.Serializer;
using System.Text.Json;

namespace Algolia.Search.Models.Search;

/// <summary>
/// widgets returned from any rules that are applied to the current search.
/// </summary>
public partial class Widgets
{
  /// <summary>
  /// Initializes a new instance of the Widgets class.
  /// </summary>
  public Widgets()
  {
  }

  /// <summary>
  /// Gets or Sets Banners
  /// </summary>
  [JsonPropertyName("banners")]
  public Banners Banners { get; set; } // this is where the issue is, this should be a list of type banner

  /// <summary>
  /// Returns the string presentation of the object
  /// </summary>
  /// <returns>String presentation of the object</returns>
  public override string ToString()
  {
    StringBuilder sb = new StringBuilder();
    sb.Append("class Widgets {\n");
    sb.Append("  Banners: ").Append(Banners).Append("\n");
    sb.Append("}\n");
    return sb.ToString();
  }

  /// <summary>
  /// Returns the JSON string presentation of the object
  /// </summary>
  /// <returns>JSON string presentation of the object</returns>
  public virtual string ToJson()
  {
    return JsonSerializer.Serialize(this, JsonConfig.Options);
  }

  /// <summary>
  /// Returns true if objects are equal
  /// </summary>
  /// <param name="obj">Object to be compared</param>
  /// <returns>Boolean</returns>
  public override bool Equals(object obj)
  {
    if (obj is not Widgets input)
    {
      return false;
    }

    return
        (Banners == input.Banners || (Banners != null && Banners.Equals(input.Banners)));
  }

  /// <summary>
  /// Gets the hash code
  /// </summary>
  /// <returns>Hash code</returns>
  public override int GetHashCode()
  {
    unchecked // Overflow is fine, just wrap
    {
      int hashCode = 41;
      if (Banners != null)
      {
        hashCode = (hashCode * 59) + Banners.GetHashCode();
      }
      return hashCode;
    }
  }

}

Its the same case for the urls in the BannerImage.cs, it should be a list of strings.

Language

CSharp

Client

Search

Steps to reproduce

  1. Go to the merchandising studio and create a rule that should return a banner for a given query
  2. Execute the query you specified in step 1 through the .NET client
  3. The client will fail to deserialize the json response from the api

Relevant log output

Algolia.Search.Exceptions.AlgoliaException: Error while deserializing response of type Algolia.Search.Models.Search.SearchResponses`1[Komplett.Integrations.SearchEngine.AlgoliaIndexedProductDto]
       ---> System.IO.InvalidDataException: The JSON string cannot be deserialized into any schema defined.                                                                                             
         at Algolia.Search.Models.Search.SearchResultJsonConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)                                                    
         at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
         at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
         at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
         at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
         at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
         at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
         at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
         at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObject(Utf8JsonReader& reader, ReadStack& state)
         at System.Text.Json.JsonSerializer.ReadFromSpanAsObject(ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
         at System.Text.Json.JsonSerializer.ReadFromSpanAsObject(ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
         at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options)
         at Algolia.Search.Serializer.DefaultJsonSerializer.Deserialize(Stream response, Type type)
         --- End of inner exception stack trace ---
         at Algolia.Search.Serializer.DefaultJsonSerializer.Deserialize(Stream response, Type type)
         at Algolia.Search.Serializer.DefaultJsonSerializer.Deserialize[T](Stream response)
         at Algolia.Search.Transport.HttpTransport.ExecuteRequestAsync[TResult,TData](HttpMethod method, String uri, InternalRequestOptions requestOptions, CancellationToken ct)
         at Algolia.Search.Transport.HttpTransport.ExecuteRequestAsync[TResult](HttpMethod method, String uri, InternalRequestOptions requestOptions, CancellationToken ct)
         at Algolia.Search.Clients.SearchClient.SearchAsync[T](SearchMethodParams searchMethodParams, RequestOptions options, CancellationToken cancellationToken)

Self-service

  • I'd be willing to fix this bug myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions