CXuesong / WikiClientLibrary

/*🌻*/ Wiki Client Library is an asynchronous MediaWiki API client library targeting modern .NET platforms
https://github.com/CXuesong/WikiClientLibrary/wiki
Apache License 2.0
80 stars 16 forks source link

Load and save entities from JSON #97

Closed miloush closed 1 year ago

miloush commented 1 year ago

It would be useful to be able to store and load entities locally. JSON seems to be easiest option since Entity.LoadFromJson seems to be already there, ToJson() or similar could be added, and the contract classes would be also helpful to have public.

CXuesong commented 1 year ago

There is a SerializableEntity class used to parse dumped Wikibase entities. See [Wikibase] Working with JSON dump .

Moreover, you can use SerializableEntity.Load method to create a SerializableEntity from IEntity (i.e., Entity or another SerializableEntity). This means after converting any entity into SerializableEntity, you can later convert it into JSON with ToJsonString / WriteTo / ToJObject methods.

miloush commented 1 year ago

Thank you! Not sure why there is a separation of SerializableEntity and Entity instead of the latter just being serializable, but this seems to address my original request. Might be worth mentioning in the documentation for Entity - I didn't check Working with JSON dump because I don't actually have any dump, my bad.