Class NHibernateProxyJsonConverter
- Namespace
- Breeze.Persistence.NH
- Assembly
- Breeze.Persistence.NH.dll
JsonConverter for handling NHibernate proxies.
Only serializes the object if it is initialized, i.e. the proxied object has been loaded.
public class NHibernateProxyJsonConverter : JsonConverter
- Inheritance
-
JsonConverterNHibernateProxyJsonConverter
- Inherited Members
-
JsonConverter.CanReadJsonConverter.CanWrite
Methods
CanConvert(Type)
Handles NHibernate proxy types.
public override bool CanConvert(Type objectType)
Parameters
objectTypeTypeThe type being considered.
Returns
- bool
True if the type is an INHibernateProxy.
ReadJson(JsonReader, Type, object?, JsonSerializer)
Not supported: proxies are written to the client but never read back from it.
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
Parameters
readerJsonReaderThe reader positioned at the value.
objectTypeTypeThe target type.
existingValueobjectAny value already present.
serializerJsonSerializerThe serializer in use.
Returns
- object
Never returns.
Exceptions
- NotImplementedException
Always.
WriteJson(JsonWriter, object?, JsonSerializer)
Write a proxied entity, unwrapping the proxy first, and write null for one that was never loaded.
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
Parameters
writerJsonWriterThe writer to write to.
valueobjectThe proxy, or the entity behind it.
serializerJsonSerializerThe serializer in use.
Remarks
An entity already written in this payload is written again as a "$ref" pointing at it. That has to be done by hand here, because a converter bypasses the reference handling Json.NET would otherwise apply.