Skip to content

Commit

Permalink
fix: fix returned type in GetSdValueByKey (box/box-codegen#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build committed Nov 29, 2024
1 parent d6b2ca4 commit 81145c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "5a3b4bc", "specHash": "544d370", "version": "1.4.0" }
{ "engineHash": "ca891f7", "specHash": "544d370", "version": "1.4.0" }
44 changes: 22 additions & 22 deletions Box.Sdk.Gen/Serialization/Json/JsonUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,30 @@ internal static string SdToUrlParams(SerializedData data)
/// <param name="obj">The SerializedData object.</param>
/// <param name="key">The key to look for in the serialized data.</param>
/// <returns>The value as a string if found; otherwise, null.</returns>
public static string GetSdValueByKey(SerializedData obj, string key)
public static string? GetSdValueByKey(SerializedData obj, string key)
{
try
{
if (obj.IsJson)
{
var jsonData = obj.AsJson();
var dictionary = JsonSerializer.Deserialize<Dictionary<string, object>>(jsonData);
if (dictionary != null && dictionary.TryGetValue(key, out var value))
{
return value?.ToString();
}
}
else
{
throw new NotSupportedException("Only JSON data is currently supported.");
}
}
catch (Exception ex)
{
throw new InvalidOperationException($"Failed to retrieve value by key '{key}' from SerializedData.", ex);
}
try
{
if (obj.IsJson)
{
var jsonData = obj.AsJson();
var dictionary = JsonSerializer.Deserialize<Dictionary<string, object>>(jsonData);
if (dictionary != null && dictionary.TryGetValue(key, out var value))
{
return value?.ToString();
}
}
else
{
throw new NotSupportedException("Only JSON data is currently supported.");
}
}
catch (Exception ex)
{
throw new InvalidOperationException($"Failed to retrieve value by key '{key}' from SerializedData.", ex);
}

return null;
return null;
}
}
}

0 comments on commit 81145c8

Please sign in to comment.