Skip to content

JSON Serialization

For objects that don’t have the [Reflector] attribute, you can opt into a runtime reflection fallback. Property reflection is lazy-loaded — it won’t inspect the type until you actually access a property.

var reflector = someObject.GetReflector(fallbackToTrueReflection: true);

Use ReflectorJsonConverter for AOT-safe System.Text.Json serialization that doesn’t rely on runtime reflection:

var options = new JsonSerializerOptions();
// Factory converter — works for all [Reflector] types
options.Converters.Add(new ReflectorJsonConverter());
// Or target a specific type
options.Converters.Add(new ReflectorJsonConverter<MyModel>());
var json = JsonSerializer.Serialize(model, options);
var deserialized = JsonSerializer.Deserialize<MyModel>(json, options);