Added non-generic registration interface to IKernel and IWindsor to accommodate dynam...
[castle.git] / MonoRail / Castle.MonoRail.Framework / Services / NewtonsoftJSONSerializer.cs
blob4aa3870bc3659042e6510a5ba216a0552fad4a0f
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Services
17 using System;
18 using Newtonsoft.Json;
20 /// <summary>
21 /// Pendent
22 /// </summary>
23 public class NewtonsoftJSONSerializer : IJSONSerializer
25 /// <summary>
26 /// Serializes the specified object.
27 /// </summary>
28 /// <param name="target">The object.</param>
29 /// <returns></returns>
30 public string Serialize(object target)
32 return JavaScriptConvert.SerializeObject(target);
35 /// <summary>
36 /// Deserializes the specified object.
37 /// </summary>
38 /// <param name="jsonString">The json representation of an object string.</param>
39 /// <param name="expectedType">The expected type.</param>
40 /// <returns></returns>
41 public object Deserialize(string jsonString, Type expectedType)
43 return JavaScriptConvert.DeserializeObject(jsonString, expectedType);
46 /// <summary>
47 /// Deserializes the specified object.
48 /// </summary>
49 /// <typeparam name="T"></typeparam>
50 /// <param name="jsonString">The json representation of an object string.</param>
51 /// <returns></returns>
52 public T Deserialize<T>(string jsonString)
54 return (T) JavaScriptConvert.DeserializeObject(jsonString, typeof(T));
57 /// <summary>
58 /// Deserializes the specified object.
59 /// </summary>
60 /// <typeparam name="T"></typeparam>
61 /// <param name="jsonString">The json representation of an object string.</param>
62 /// <returns></returns>
63 public T[] DeserializeArray<T>(string jsonString)
65 return (T[]) JavaScriptConvert.DeserializeObject(jsonString, typeof(T));