I get the error when transforming the JSON returned from GetObjectHF to Object with fastJSON, but I think the error is related to raptorDB.
Here's the stack trace :
System.Exception: Unexpectedly reached end of string
à fastJSON.JsonParser.ParseString(Char* p, Boolean val)
à fastJSON.JsonParser.ParseValue(Char* p, Boolean val)
à fastJSON.JsonParser.ParseObject(Char* p)
à fastJSON.JsonParser.ParseValue(Char* p, Boolean val)
à fastJSON.JsonParser.ParseArray(Char* p)
à fastJSON.JsonParser.ParseValue(Char* p, Boolean val)
à fastJSON.JsonParser.Decode()
à fastJSON.deserializer.ToObject(String json, Type type)
à fastJSON.deserializer.ToObject[T](String json)
à fastJSON.JSON.ToObject[T](String json)
Here's my code:
public class BaseRepository<T>
{
protected IRaptorDB DB;
public BaseRepository(IRaptorDB DB)
{
this.DB = DB ?? throw new ArgumentNullException(nameof(DB));
}
protected virtual string Key { get; }
public T GetObjectFromKeyStore()
{
IKeyStoreHF keystore = this.DB.GetKVHF();
object o;
if (keystore == null)
return default(T);
o = keystore.GetObjectHF(Key);
if (o == null)
return default(T);
return fastJSON.JSON.ToObject<T>(o.ToString());
}
public bool SetObjectToKeyStore(T obj)
{
IKeyStoreHF keystore = this.DB.GetKVHF();
return keystore.SetObjectHF(Key, fastJSON.JSON.ToJSON(obj));
}
}
It happens randomly and re-writing the document without changing the JSON or deleting the DB folder and starting fresh fixes the issue, but it's not a solution.
What makes me think the problem is with RaptorDB and not fastJSON is that to me it's seems that the string returned by GetObjectHF is badly formatted.
Here's an example of a string that gives this error:
"[{"$type":"domaine.Engin, domaine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"XXXFIELD":"XXXX\\483deeab-1ce8-4c79-b45f-588785e0e1e4","Codes":"S50","Nom":"XNON ","CodeDepot":null,"Marqueurs":"",
"Description":"S50 - MINIPELLE CATERPILLAR PAYEN ","Code":"S50","RessourceOid":1139,"PlanningXXXFIELD":null},{"$type":"domaine.Engin, domaine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nu潬祲itaux ","Adresse":""},
{"$type":"1","XXXFIELD":"XXXX\\f704e193-95b5-4bc2-b427-115dbf5affac","Code":"530007","Nom":"530007 Chantiers \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
There are many more \0\0 in the end, I excluded to make it more readable.
System.Exception: Expected colon at index 29340
à fastJSON.JsonParser.ParseObject(Char* p)
à fastJSON.JsonParser.ParseValue(Char* p, Boolean val)
à fastJSON.JsonParser.ParseArray(Char* p)
à fastJSON.JsonParser.ParseValue(Char* p, Boolean val)
à fastJSON.JsonParser.Decode()
à fastJSON.deserializer.ToObject(String json, Type type)
à fastJSON.deserializer.ToObject[T](String json)
à fastJSON.JSON.ToObject[T](String json)
This is a related error that happens randomly but again, the JSON returned seems to be badly formatted.
"[{"$type":"domaine.Engin, domaine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","XXXField":"XXXXX\\483deeab-1ce8-4c79-b45f-588785e0e1e4","Codes":"S50","Nom":"MINIPELLE CATERPILLAR PublicKeyToken=null","XXXField":"XXXXX\\49b3598a-fca5-43df-b262-7bc4eb9fb120","C"
I'd love some help.
Thank you in advance.