Created
March 29, 2013 05:09
-
-
Save anonymous/5268878 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NewtonSoftJsonResult : JsonResult | |
{ | |
public override void ExecuteResult(ControllerContext context) | |
{ | |
if (context == null) | |
throw new ArgumentNullException("context"); | |
var response = context.HttpContext.Response; | |
response.ContentType = ContentType; | |
response.ContentEncoding = ContentEncoding; | |
if (Data == null) | |
return; | |
var serializer = new JsonSerializerSettings | |
{ | |
ReferenceLoopHandling = ReferenceLoopHandling.Ignore, | |
ContractResolver = new NHibernateContractResolver() | |
}; | |
string serializedObject = JsonConvert.SerializeObject(Data, serializer); | |
response.Write(serializedObject); | |
} | |
} | |
public class NHibernateContractResolver : DefaultContractResolver | |
{ | |
protected override JsonContract CreateContract(Type objectType) | |
{ | |
if (typeof(NHibernate.Proxy.INHibernateProxy).IsAssignableFrom(objectType)) | |
return base.CreateContract(objectType.BaseType); | |
else | |
return base.CreateContract(objectType); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment