1
// Copyright 2004-2008 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
21 /// Abstracts the underlying JSON writer
23 public interface IJSONWriter
26 /// Writes the start object.
28 void WriteStartObject();
30 /// Writes the end object.
32 void WriteEndObject();
34 /// Writes the start array.
36 void WriteStartArray();
38 /// Writes the end array.
42 /// Writes the name of the property.
44 /// <param name="name">The name.</param>
45 void WritePropertyName(string name
);
55 /// Writes the undefined.
57 void WriteUndefined();
61 /// <param name="javaScript">The java script.</param>
62 void WriteRaw(string javaScript
);
66 /// <param name="value">The value.</param>
67 void WriteValue(object value);
71 /// <param name="value">The value.</param>
72 void WriteValue(string value);
76 /// <param name="value">The value.</param>
77 void WriteValue(int value);
81 /// <param name="value">The value.</param>
82 void WriteValue(long value);
86 /// <param name="value">The value.</param>
87 void WriteValue(float value);
91 /// <param name="value">if set to <c>true</c> [value].</param>
92 void WriteValue(bool value);
96 /// <param name="value">The value.</param>
97 void WriteValue(short value);
101 /// <param name="value">The value.</param>
102 void WriteValue(decimal value);
105 /// Writes the value.
107 /// <param name="value">The value.</param>
108 void WriteValue(DateTime
value);
114 public interface IJSONConverter
117 /// Writes the specified value using the writer.
119 /// <param name="writer">The writer.</param>
120 /// <param name="value">The value.</param>
121 void Write(IJSONWriter writer
, object value);
124 /// Determines whether this instance can handle the specified type.
126 /// <param name="type">The type.</param>
128 /// <c>true</c> if this instance can handle the specified type; otherwise, <c>false</c>.
130 bool CanHandle(Type type
);
134 /// Converts the JSON read by the supplied reader into an instance of the requested type.
136 /// <param name="reader">The reader.</param>
137 /// <param name="objectType">The type.</param>
138 /// <returns></returns>
139 object ReadJson(IJSONReader reader
, Type objectType
);
146 public interface IJSONSerializer
149 /// Serializes the specified object.
151 /// <param name="target">The object.</param>
152 /// <returns></returns>
153 string Serialize(object target
);
156 /// Serializes the specified object.
158 /// <param name="target">The object.</param>
159 /// <param name="converters">The converters.</param>
160 /// <returns></returns>
161 string Serialize(object target
, params IJSONConverter
[] converters
);
164 /// Serializes the specified object.
166 /// <param name="target">The target.</param>
167 /// <param name="writer">The writer.</param>
168 /// <param name="converters">The converters.</param>
169 void Serialize(object target
, TextWriter writer
, params IJSONConverter
[] converters
);
172 /// Deserializes the specified object.
174 /// <param name="jsonString">The json representation of an object string.</param>
175 /// <param name="expectedType">The expected type.</param>
176 /// <returns></returns>
177 object Deserialize(string jsonString
, Type expectedType
);
180 /// Deserializes the specified object.
182 /// <param name="jsonString">The json representation of an object string.</param>
183 /// <returns></returns>
184 T Deserialize
<T
>(string jsonString
);
187 /// Deserializes the specified object.
189 /// <param name="jsonString">The json representation of an object string.</param>
190 /// <returns></returns>
191 T
[] DeserializeArray
<T
>(string jsonString
);
196 /// Represents a reader that provides fast, non-cached, forward-only access to serialized Json data.
198 public interface IJSONReader
201 /// Gets the quotation mark character used to enclose the value of a string.
203 char QuoteChar { get; }
206 /// Gets the text value of the current Json token.
208 object Value { get; }
211 /// Gets The Common Language Runtime (CLR) type for the current Json token.
213 Type ValueType { get; }
221 /// Reads the next Json token from the stream.
223 /// <returns></returns>
232 /// Changes the <see cref="Newtonsoft.Json.JsonReader.State"/> to Closed.