Closed Isaac-Guillen closed 2 weeks ago
Hello @Isaac-Guillen
This error happens because you are using the Record id in your ASP.NET web App/API and as such the Record id is serialized to/deserialized from json.
Serializing a Record id is pretty easy in general because we only have to extract the id part of a RecordId
. However, deserializing is another story.
The default JSON converter used is ReadOnlyRecordIdJsonConverter
. See: https://github.com/surrealdb/surrealdb.net/blob/abb7c4de3c504a6e99584f8c1dc5d8aff2091aba/SurrealDb.Net/Models/Record.cs#L15
This converter like its name implies only read and serializes the id from the RecordId
POCO and outputs it to JSON. But it is not able to read/deserialize from JSON and deduce how to create a RecordId
from the JSON input.
From that, you have two solutions:
Record
inherited classRecordIdJsonConverterAttribute
https://github.com/surrealdb/surrealdb.net/blob/abb7c4de3c504a6e99584f8c1dc5d8aff2091aba/SurrealDb.Net/Json/RecordIdJsonConverterAttribute.cs#L6The first solution is pretty easy but I can acknowledge it needs more work.
For the second solution, you simply need to override the Id
property to use the RecordIdJsonConverterAttribute
. See example below:
public class MyRecord : Record
{
[RecordIdJsonConverter("my-table")]
[CborProperty("id")]
[CborIgnoreIfDefault]
public new RecordId? Id { get; set; }
}
The table argument of the attribute is required to determine what table the RecordId belong to.
Feel free to ask any question on this matter.
Thank you for the response and solutions proposed, I think that in long term would be better to implement DTO Models and mappers, but in the short term, the override solution has any downside?
Thanks!
Thank you for the response and solutions proposed, I think that in long term would be better to implement DTO Models and mappers, but in the short term, the override solution has any downside?
I do not know if there is any.
Thanks a lot for your help!
Is your feature request related to a problem?
I have a blazor app that receives models from the backend, but now I get an error saying ReadOnlyRecordIdJsonConverter.Read is not implemented, I don't know what to do without having a great impact in my project
Describe the solution
I think this will be resolved once the read method is implemented
Alternative methods
I don't know if there is a way to override the method or I have to do anything else
SurrealDB version
2
Package version(s)
El proyecto "Demo.Server" tiene las referencias de paquete siguientes [net8.0]: Paquete de nivel superior Solicitado Resuelto
El proyecto "Demo.Shared" tiene las referencias de paquete siguientes [net8.0]: Paquete de nivel superior Solicitado Resuelto
El proyecto "Demo.Client" tiene las referencias de paquete siguientes [net8.0]: Paquete de nivel superior Solicitado Resuelto
Contact Details
isaac.guillen@proton.me
Is there an existing issue for this?
Code of Conduct