Skip to content

Commit

Permalink
fix(kotlin): deserialization (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3822

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
  • Loading branch information
algolia-bot and Fluf22 committed Sep 23, 2024
1 parent f2feb75 commit 08f9c34
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions algoliasearch/Models/Recommend/RecommendationsHit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ public partial class RecommendationsHit : AbstractSchema
{
/// <summary>
/// Initializes a new instance of the RecommendationsHit class
/// with a RecommendHit
/// with a TrendingFacetHit
/// </summary>
/// <param name="actualInstance">An instance of RecommendHit.</param>
public RecommendationsHit(RecommendHit actualInstance)
/// <param name="actualInstance">An instance of TrendingFacetHit.</param>
public RecommendationsHit(TrendingFacetHit actualInstance)
{
ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}

/// <summary>
/// Initializes a new instance of the RecommendationsHit class
/// with a TrendingFacetHit
/// with a RecommendHit
/// </summary>
/// <param name="actualInstance">An instance of TrendingFacetHit.</param>
public RecommendationsHit(TrendingFacetHit actualInstance)
/// <param name="actualInstance">An instance of RecommendHit.</param>
public RecommendationsHit(RecommendHit actualInstance)
{
ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
Expand All @@ -47,42 +47,42 @@ public RecommendationsHit(TrendingFacetHit actualInstance)
public sealed override object ActualInstance { get; set; }

/// <summary>
/// Get the actual instance of `RecommendHit`. If the actual instance is not `RecommendHit`,
/// Get the actual instance of `TrendingFacetHit`. If the actual instance is not `TrendingFacetHit`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of RecommendHit</returns>
public RecommendHit AsRecommendHit()
/// <returns>An instance of TrendingFacetHit</returns>
public TrendingFacetHit AsTrendingFacetHit()
{
return (RecommendHit)ActualInstance;
return (TrendingFacetHit)ActualInstance;
}

/// <summary>
/// Get the actual instance of `TrendingFacetHit`. If the actual instance is not `TrendingFacetHit`,
/// Get the actual instance of `RecommendHit`. If the actual instance is not `RecommendHit`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of TrendingFacetHit</returns>
public TrendingFacetHit AsTrendingFacetHit()
/// <returns>An instance of RecommendHit</returns>
public RecommendHit AsRecommendHit()
{
return (TrendingFacetHit)ActualInstance;
return (RecommendHit)ActualInstance;
}


/// <summary>
/// Check if the actual instance is of `RecommendHit` type.
/// Check if the actual instance is of `TrendingFacetHit` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsRecommendHit()
public bool IsTrendingFacetHit()
{
return ActualInstance.GetType() == typeof(RecommendHit);
return ActualInstance.GetType() == typeof(TrendingFacetHit);
}

/// <summary>
/// Check if the actual instance is of `TrendingFacetHit` type.
/// Check if the actual instance is of `RecommendHit` type.
/// </summary>
/// <returns>Whether or not the instance is the type</returns>
public bool IsTrendingFacetHit()
public bool IsRecommendHit()
{
return ActualInstance.GetType() == typeof(TrendingFacetHit);
return ActualInstance.GetType() == typeof(RecommendHit);
}

/// <summary>
Expand Down Expand Up @@ -169,28 +169,28 @@ public override RecommendationsHit Read(ref Utf8JsonReader reader, Type typeToCo
{
var jsonDocument = JsonDocument.ParseValue(ref reader);
var root = jsonDocument.RootElement;
if (root.ValueKind == JsonValueKind.Object)
if (root.ValueKind == JsonValueKind.Object && root.TryGetProperty("facetName", out _) && root.TryGetProperty("facetValue", out _))
{
try
{
return new RecommendationsHit(jsonDocument.Deserialize<RecommendHit>(JsonConfig.Options));
return new RecommendationsHit(jsonDocument.Deserialize<TrendingFacetHit>(JsonConfig.Options));
}
catch (Exception exception)
{
// deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into RecommendHit: {exception}");
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into TrendingFacetHit: {exception}");
}
}
if (root.ValueKind == JsonValueKind.Object)
{
try
{
return new RecommendationsHit(jsonDocument.Deserialize<TrendingFacetHit>(JsonConfig.Options));
return new RecommendationsHit(jsonDocument.Deserialize<RecommendHit>(JsonConfig.Options));
}
catch (Exception exception)
{
// deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into TrendingFacetHit: {exception}");
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into RecommendHit: {exception}");
}
}
throw new InvalidDataException($"The JSON string cannot be deserialized into any schema defined.");
Expand Down

0 comments on commit 08f9c34

Please sign in to comment.