Closed Krakean closed 5 years ago
a) What alternatives to Json.net's attributes - [Newtonsoft.Json.JsonRequiredAttribute()] and [Newtonsoft.Json.JsonPropertyAttribute("blabla")] - in NetJSON?
public class SampleSubstitionClass { [NetJSONProperty("blahblah")] public string Name { get; set; } [NetJSONProperty("foobar")] public int ID { get; set; }
[NetJSONProperty("barfoo")]
public int Number;
}
For other customization, you can use NetJSON.CanSerialize and NetJSON.SerializeAs to specify your own custom property for naming properties such as the use of Component Model attribute such as DataMember(...). Example of using CanSerialize is below
NetJSON.CanSerialize = CanSerialize; public class TestClassWithIgnoreAttr { [TestIgnore] public int ID { get; set; } }
public class TestIgnoreAttribute : Attribute
{
}
private static bool CanSerialize(MemberInfo memberInfo)
{
var attr = memberInfo.GetCustomAttribute
return true;
}
b) Alternatives to Json.Net's "JsonToken", "JsonReader", "JsonSerializer" and "JsonWriter" in NetJSON?
I currently don't support any custom json reader. The logic of how it currently deals with json data are only kept as internal methods. I have not seen a use of having them exposed other side. In terms of using a stream writer/reader. I have override methods for serialize and deserialize that works with any TextWriter/TextReader implementation for saving and loading of json. Just note that the current implementation does not do streaming but rather just read everything into memory which can be an issue. I can look into supporting streaming later which will make me to support the features you requested above.
c) Alternative to Json.Net's "JsonConverter" class in NetJSON?
I have
RegisterTypeSerializer<T>(Func<T, string> serializeFunc)
from (https://github.com/rpgmaker/NetJSON/wiki/Quick-Guide) which allow you to create custom type serialization of specific types used when dealing with dictionary[string, object]. Its focus was originally for type of object, but can be enabled easily to work with all types regardless of whether it is object or not. For this option, you can submit a ticket for me to enable it.
@Krakean , if my statement answer your questions please let me know and close this ticket out. If any tickets need to be open in correlation to the questions please create them.
Thanks,
Closing since there has been no activity for a while. Please reopen if needed.
Thanks,
@rpgmaker Hello I would like to migrate gfTF-CSharp-Loader (https://github.com/KhronosGroup/glTF-CSharp-Loader) from using Newton's Json.Net to your NetJSON, but i have couple of questions, please help me with them: a) What alternatives to Json.net's attributes - [Newtonsoft.Json.JsonRequiredAttribute()] and [Newtonsoft.Json.JsonPropertyAttribute("blabla")] - in NetJSON? b) Alternatives to Json.Net's "JsonToken", "JsonReader", "JsonSerializer" and "JsonWriter" in NetJSON? c) Alternative to Json.Net's "JsonConverter" class in NetJSON?
Thanks for your attention