Skip to content

Error when record class has an object type property #84

Closed
@saulgaray0131

Description

@saulgaray0131

Not able to have an object property in a record class.

Tested using the test server project by adding an object type property to Person class.

public class Person : MagicTableTool<Person>, IMagicTable<DbSets>
{
   /// Add this
    public object Payload { get; set; } = new { Property = "test" };
}

Error:

Error handling streamed JS: SyntaxError: Expected ',' or '}' after property value in JSON at position 334 (line 1 column 335)
    at JSON.parse (<anonymous>)
    at magicDbMethods.3z1shsk3oa.js:77:59
    at Array.map (<anonymous>)
    at Module.streamedJsHandler (magicDbMethods.3z1shsk3oa.js:77:41)
---------------------------------------------------------------------------------------------------------
[2025-04-05T20:47:51.125Z] Error: System.Text.Json.JsonException: The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 1.
 ---> System.InvalidOperationException: Cannot get the value of a token type 'StartObject' as a boolean.
   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedBoolean(JsonTokenType tokenType)
   at System.Text.Json.Utf8JsonReader.GetBoolean()
   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, T& value, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, T& value, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObject(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadAsObject(Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo)
   at Magic.IndexedDb.Models.MagicContractResolver`1.ReadSimpleType(Utf8JsonReader& reader, Type type) in C:\VSTS\magiccodingman\Magic.IndexedDb\Magic.IndexedDb\Models\MagicContractResolver.cs:line 217
   at Magic.IndexedDb.Models.MagicContractResolver`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) in C:\VSTS\magiccodingman\Magic.IndexedDb\Magic.IndexedDb\Models\MagicContractResolver.cs:line 25
   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, T& value, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo`1 jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
   at Magic.IndexedDb.Helpers.MagicSerializationHelper.DeserializeObject[T](String json, MagicJsonSerializationSettings settings) in C:\VSTS\magiccodingman\Magic.IndexedDb\Magic.IndexedDb\Helpers\MagicSerializationHelper.cs:line 83
   at Magic.IndexedDb.Extensions.MagicJsInvoke.TrueMagicStreamJsAsync[T](String modulePath, String functionName, CancellationToken token, Boolean isVoid, ITypedArgument[] args) in C:\VSTS\magiccodingman\Magic.IndexedDb\Magic.IndexedDb\Extensions\MagicJsInvoke.cs:line 141
   at Magic.IndexedDb.Extensions.MagicJsInvoke.TrueMagicStreamJsAsync[T](String modulePath, String functionName, CancellationToken token, Boolean isVoid, ITypedArgument[] args) in C:\VSTS\magiccodingman\Magic.IndexedDb\Magic.IndexedDb\Extensions\MagicJsInvoke.cs:line 141
   at Magic.IndexedDb.Extensions.MagicJsInvoke.MagicVoidStreamJsAsync(String modulePath, String functionName, CancellationToken token, ITypedArgument[] args) in C:\VSTS\magiccodingman\Magic.IndexedDb\Magic.IndexedDb\Extensions\MagicJsInvoke.cs:line 248
   at Magic.IndexedDb.Extensions.MagicJsInvoke.CallJsAsync(String modulePath, String functionName, CancellationToken token, ITypedArgument[] args) in C:\VSTS\magiccodingman\Magic.IndexedDb\Magic.IndexedDb\Extensions\MagicJsInvoke.cs:line 28
   at Magic.IndexedDb.MagicQuery`1.AddRangeAsync(IEnumerable`1 records, CancellationToken cancellationToken) in C:\VSTS\magiccodingman\Magic.IndexedDb\Magic.IndexedDb\LinqTranslation\Models\MagicQuery.cs:line 146
   at TestServer.Components.Pages.Home.OnAfterRenderAsync(Boolean firstRender) in C:\VSTS\magiccodingman\Magic.IndexedDb\TestServer\TestServer\Components\Pages\Home.razor:line 255
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions