Permalink
Browse files

Merge branch 'master' of github.com:ServiceStack/ServiceStack.Text

  • Loading branch information...
2 parents 5412f33 + 6674eb2 commit 0c1c173454fb611b39fc526195bde2f05aec3fe5 @desunit desunit committed Mar 27, 2013
@@ -3,7 +3,7 @@
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>ServiceStack.Text</id>
<title>.NET's fastest JSON Serializer by ServiceStack</title>
- <version>3.9.38</version>
+ <version>3.9.42</version>
<authors>Demis Bellot</authors>
<owners>Demis Bellot</owners>
<summary>.NET's fastest JSON, JSV and CSV Text Serializers (3x faster than JSON.NET)</summary>
View
@@ -448,3 +448,10 @@ A value with a double-quote is escaped with another double quote e.g:
To better illustrate the resilience of `TypeSerializer` and the JSV Format check out a real world example of it when it's used to [Painlessly migrate between old and new types in Redis](https://github.com/ServiceStack/ServiceStack.Redis/wiki/MigrationsUsingSchemalessNoSql).
Support for dynamic payloads and late-bound objects is explained in the post [Versatility of JSV Late-bound objects](http://www.servicestack.net/mythz_blog/?p=314).
+
+
+# Community Resources
+
+ - [ServiceStack.Text has nice extension method called Dump and has a few friends](http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/servicestack-text-has-a-nice) by [@chrissie1](https://twitter.com/chrissie1)
+ - [JSON.NET vs ServiceStack](http://daniel.wertheim.se/2011/02/07/json-net-vs-servicestack/)
+ - [GithubSharp with ServiceStack.Text](http://xtzgzorex.wordpress.com/2012/01/30/githubsharp-with-servicestack-text/) by [@XTZGZoReX](https://twitter.com/XTZGZoReX)
@@ -26,7 +26,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
+ <DefineConstants>TRACE;NET40</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@@ -0,0 +1,3 @@
+<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
+ <s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String>
+ <s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String></wpf:ResourceDictionary>
@@ -37,8 +37,8 @@ public override TypeAccessor GetTypeAccessorForProperty(string propertyName, Dic
private static string TransformFromLowercaseUnderscore(string propertyName)
{
- // "lowercase_underscore" -> LowercaseUnderscore
- return propertyName.ToTitleCase();
+ // "lowercase-hyphen" -> "lowercase_underscore" -> LowercaseUnderscore
+ return propertyName.Replace("-","_").ToTitleCase();
}
}
@@ -83,11 +83,6 @@ internal static void WriteItemSeperatorIfRanOnce(TextWriter writer, ref bool ran
writer.Write(ItemSeperator);
else
ranOnce = true;
-
- foreach (var escapeChar in EscapeChars)
- {
- EscapeCharFlags[escapeChar] = true;
- }
}
internal static bool ShouldUseDefaultToStringMethod(Type type)
@@ -210,7 +210,7 @@ public static void WriteList(TextWriter writer, object oList)
public static void WriteGenericList(TextWriter writer, List<T> list)
{
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
var ranOnce = false;
var listLength = list.Count;
@@ -220,7 +220,7 @@ public static void WriteGenericList(TextWriter writer, List<T> list)
ElementWriteFn(writer, list[i]);
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
public static void WriteListValueType(TextWriter writer, object list)
@@ -232,7 +232,7 @@ public static void WriteGenericListValueType(TextWriter writer, List<T> list)
{
if (list == null) return; //AOT
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
var ranOnce = false;
var listLength = list.Count;
@@ -242,7 +242,7 @@ public static void WriteGenericListValueType(TextWriter writer, List<T> list)
ElementWriteFn(writer, list[i]);
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
public static void WriteIList(TextWriter writer, object oList)
@@ -253,7 +253,7 @@ public static void WriteIList(TextWriter writer, object oList)
public static void WriteGenericIList(TextWriter writer, IList<T> list)
{
if (list == null) return;
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
var ranOnce = false;
var listLength = list.Count;
@@ -271,7 +271,7 @@ public static void WriteGenericIList(TextWriter writer, IList<T> list)
Tracer.Instance.WriteError(ex);
throw;
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
public static void WriteIListValueType(TextWriter writer, object list)
@@ -283,7 +283,7 @@ public static void WriteGenericIListValueType(TextWriter writer, IList<T> list)
{
if (list == null) return; //AOT
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
var ranOnce = false;
var listLength = list.Count;
@@ -293,7 +293,7 @@ public static void WriteGenericIListValueType(TextWriter writer, IList<T> list)
ElementWriteFn(writer, list[i]);
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
public static void WriteArray(TextWriter writer, object oArrayValue)
@@ -310,7 +310,7 @@ public static void WriteGenericArrayValueType(TextWriter writer, object oArray)
public static void WriteGenericArrayValueType(TextWriter writer, T[] array)
{
if (array == null) return;
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
var ranOnce = false;
var arrayLength = array.Length;
@@ -320,13 +320,13 @@ public static void WriteGenericArrayValueType(TextWriter writer, T[] array)
ElementWriteFn(writer, array[i]);
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
private static void WriteGenericArrayMultiDimension(TextWriter writer, Array array, int rank, int[] indices)
{
var ranOnce = false;
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
for (int i = 0; i < array.GetLength(rank); i++)
{
JsWriter.WriteItemSeperatorIfRanOnce(writer, ref ranOnce);
@@ -337,7 +337,7 @@ private static void WriteGenericArrayMultiDimension(TextWriter writer, Array arr
else
ElementWriteFn(writer, array.GetValue(indices));
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
public static void WriteGenericArray(TextWriter writer, Array array)
@@ -352,7 +352,7 @@ public static void WriteEnumerable(TextWriter writer, object oEnumerable)
public static void WriteGenericEnumerable(TextWriter writer, IEnumerable<T> enumerable)
{
if (enumerable == null) return;
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
var ranOnce = false;
foreach (var value in enumerable)
@@ -361,12 +361,12 @@ public static void WriteGenericEnumerable(TextWriter writer, IEnumerable<T> enum
ElementWriteFn(writer, value);
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
public static void WriteGenericEnumerableValueType(TextWriter writer, IEnumerable<T> enumerable)
{
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
var ranOnce = false;
foreach (var value in enumerable)
@@ -375,7 +375,7 @@ public static void WriteGenericEnumerableValueType(TextWriter writer, IEnumerabl
ElementWriteFn(writer, value);
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
}
@@ -388,7 +388,7 @@ public static void WriteListString(ITypeSerializer serializer, TextWriter writer
public static void WriteListString(ITypeSerializer serializer, TextWriter writer, List<string> list)
{
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
var ranOnce = false;
foreach (var x in list)
@@ -397,7 +397,7 @@ public static void WriteListString(ITypeSerializer serializer, TextWriter writer
serializer.WriteString(writer, x);
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
public static void WriteIListString(ITypeSerializer serializer, TextWriter writer, object list)
@@ -407,7 +407,7 @@ public static void WriteIListString(ITypeSerializer serializer, TextWriter write
public static void WriteIListString(ITypeSerializer serializer, TextWriter writer, IList<string> list)
{
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
var ranOnce = false;
var listLength = list.Count;
@@ -417,7 +417,7 @@ public static void WriteIListString(ITypeSerializer serializer, TextWriter write
serializer.WriteString(writer, list[i]);
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
public static void WriteBytes(ITypeSerializer serializer, TextWriter writer, object byteValue)
@@ -428,7 +428,7 @@ public static void WriteBytes(ITypeSerializer serializer, TextWriter writer, obj
public static void WriteStringArray(ITypeSerializer serializer, TextWriter writer, object oList)
{
- writer.Write(JsWriter.ListStartChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListStartChar);
var list = (string[])oList;
var ranOnce = false;
@@ -439,7 +439,7 @@ public static void WriteStringArray(ITypeSerializer serializer, TextWriter write
serializer.WriteString(writer, list[i]);
}
- writer.Write(JsWriter.ListEndChar);
+ if (!JsState.QueryStringMode) writer.Write(JsWriter.ListEndChar);
}
}
@@ -11,6 +11,7 @@
//
using System;
+using System.Collections;
using System.IO;
using System.Reflection;
using ServiceStack.Text.Json;
@@ -1,4 +1,5 @@
#if NET40
+using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
@@ -34,7 +34,7 @@ static Env()
+ (IsWinRT ? ".NET WinRT" : "");
}
- public static decimal ServiceStackVersion = 3.938m;
+ public static decimal ServiceStackVersion = 3.942m;
public static bool IsUnix { get; set; }
@@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("3.9.38.0")]
+[assembly: AssemblyVersion("3.9.42.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -11,6 +11,7 @@
//
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
@@ -104,6 +105,11 @@ static QueryStringWriter()
{
CacheFn = QueryStringSerializer.WriteLateBoundObject;
}
+ else if (typeof (T).AssignableFrom(typeof (IDictionary))
+ || typeof (T).HasInterface(typeof (IDictionary)))
+ {
+ CacheFn = WriteIDictionary;
+ }
else
{
if (typeof(T).IsClass() || typeof(T).IsInterface())
@@ -125,6 +131,57 @@ public static void WriteObject(TextWriter writer, object value)
if (writer == null) return;
CacheFn(writer, value);
}
- }
+
+ private static readonly ITypeSerializer Serializer = JsvTypeSerializer.Instance;
+ public static void WriteIDictionary(TextWriter writer, object oMap)
+ {
+ WriteObjectDelegate writeKeyFn = null;
+ WriteObjectDelegate writeValueFn = null;
+
+ try
+ {
+ JsState.QueryStringMode = true;
+
+ var map = (IDictionary)oMap;
+ var ranOnce = false;
+ foreach (var key in map.Keys)
+ {
+ var dictionaryValue = map[key];
+ if (dictionaryValue == null) continue;
+
+ if (writeKeyFn == null)
+ {
+ var keyType = key.GetType();
+ writeKeyFn = Serializer.GetWriteFn(keyType);
+ }
+
+ if (writeValueFn == null)
+ writeValueFn = Serializer.GetWriteFn(dictionaryValue.GetType());
+
+ if (ranOnce)
+ writer.Write("&");
+ else
+ ranOnce = true;
+
+ JsState.WritingKeyCount++;
+ JsState.IsWritingValue = false;
+
+ writeKeyFn(writer, key);
+
+ JsState.WritingKeyCount--;
+
+ writer.Write("=");
+
+ JsState.IsWritingValue = true;
+ writeValueFn(writer, dictionaryValue);
+ JsState.IsWritingValue = false;
+ }
+ }
+ finally
+ {
+ JsState.QueryStringMode = false;
+ }
+ }
+ }
}
@@ -121,7 +121,10 @@ public static string EncodeJson(this string value)
public static string EncodeJsv(this string value)
{
- if (JsState.QueryStringMode) value = UrlEncode(value);
+ if (JsState.QueryStringMode)
+ {
+ return UrlEncode(value);
+ }
return String.IsNullOrEmpty(value) || !JsWriter.HasAnyEscapeChars(value)
? value
: String.Concat
Oops, something went wrong.

0 comments on commit 0c1c173

Please sign in to comment.