private static object TranslateSurrogate(object deserializedValue, NewtonSoftJsonSerializer parent, Type type) { var j = deserializedValue as JObject; if (j != null) { //The JObject represents a special akka.net wrapper for primitives (int,float,decimal) to preserve correct type when deserializing if (j["$"] != null) { var value = j["$"].Value <string>(); return(GetValue(value)); } //The JObject is not of our concern, let Json.NET deserialize it. return(j.ToObject(type, parent._serializer)); } var surrogate = deserializedValue as ISurrogate; //The deserialized object is a surrogate, unwrap it if (surrogate != null) { return(surrogate.FromSurrogate(parent.system)); } return(deserializedValue); }
public void StateShouldBeSerializedAndDeserializedCorrectly(object sut) { var serializer = new NewtonSoftJsonSerializer(null); var bytes = serializer.ToBinary(sut); //var json = Encoding.Default.GetString(bytes); var result = (DeviceStoreState) serializer.FromBinary(bytes, typeof (DeviceStoreState)); result.ShouldBeEquivalentTo(sut); }
public SurrogateConverter(NewtonSoftJsonSerializer parent) { _parent = parent; }
public void An_ActorRef_should_throw_an_exception_on_deserialize_if_no_system_in_scope() { var aref = ActorOf<BlackHoleActor>(); var serializer = new NewtonSoftJsonSerializer(null); Intercept(() => { var binary = serializer.ToBinary(aref); var bref = serializer.FromBinary(binary, typeof(IActorRef)); }); }
public SurrogateConverter(NewtonSoftJsonSerializer parent) { _parent = parent; }
private static object TranslateSurrogate(object deserializedValue,NewtonSoftJsonSerializer parent,Type type) { var j = deserializedValue as JObject; if (j != null) { //The JObject represents a special akka.net wrapper for primitives (int,float,decimal) to preserve correct type when deserializing if (j["$"] != null) { var value = j["$"].Value<string>(); return GetValue(value); } //The JObject is not of our concern, let Json.NET deserialize it. return j.ToObject(type, parent._serializer); } var surrogate = deserializedValue as ISurrogate; //The deserialized object is a surrogate, unwrap it if (surrogate != null) { return surrogate.FromSurrogate(parent.system); } return deserializedValue; }