I've got an interesting situation whereby elastic v7 default utf8json has managed to serialize my object, but is unable to de-serialize it correctly.
public class MyClass : FlagsSet
{
[JsonIgnore]
public bool IsActive
{
get
{
return this.IsSet("active");
}
}
}
public class FlagsSet : ICollection<string>, IEnumerable<string>, IEnumerable
{
private readonly HashSet<string> _list = new HashSet<string>((IEqualityComparer<string>) StringComparer.InvariantCultureIgnoreCase);
...
public void Add(string item)
{
if (string.IsNullOrEmpty(item))
return;
this._list.Add(item);
}
}
If I was using json.net I'd handle this by writing a converter, but I'm not able to see an equivalent using utf8json as it appears the formatters used by the default serializer (DefaultHighLevelSerializer) are all registered internally. I've read a few pages on customer serializers (notably this one.. https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/custom-serialization.html)
So in short..
- Is it possible to register a custom utf8json formatter (i.e. similar to the json.net converter which is supported)? And if so, are you able to point me to an example please?
- Alternatively, if it's not possible then is there a way to get the utf8json deserialisation to work correctly with the above example?
Answered in the elastic discussion (as linked by Russ above).. https://discuss.elastic.co/t/does-utf8json-used-in-elastic-v7-x-support-user-defined-custom-formatters/237283/4?u=forloop
A quick summary of the answer here..
So in short, if you want the benefits of the faster utf8json serialization AND custom formatters.. then you'll need implement a custom serializer using a non-elastic specific import of the utf8json library. Alternatively if that sounds like a lot of work(!) AND/OR you're happy with the slower performing json.net (as used in NEST v6's default serializer), then you can revert to this and use the custom converters.
Forward looking though, things appear brighter as v8 NEST will likely get a 'new new' serializer which will (hopefully) support custom converter/formatters..