1
// Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using Newtonsoft
.Json
;
23 public class NewtonsoftJSONSerializer
: IJSONSerializer
26 /// Serializes the specified object.
28 /// <param name="target">The object.</param>
29 /// <returns></returns>
30 public string Serialize(object target
)
32 return JavaScriptConvert
.SerializeObject(target
);
36 /// Deserializes the specified object.
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
);
47 /// Deserializes the specified object.
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
));
58 /// Deserializes the specified object.
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
));