This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed
tests/ServiceStack.Text.Tests/Issues Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,9 @@ public static object ObjectStringToType(ReadOnlySpan<char> strType)
9494 return primitiveType ;
9595
9696 if ( Serializer . ObjectDeserializer != null && typeof ( TSerializer ) == typeof ( Json . JsonTypeSerializer ) )
97- return Serializer . ObjectDeserializer ( strType ) ;
97+ return ! strType . IsNullOrEmpty ( )
98+ ? Serializer . ObjectDeserializer ( strType )
99+ : strType . Value ( ) ;
98100
99101 return Serializer . UnescapeString ( strType ) . Value ( ) ;
100102 }
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ public static class JsonUtils
4242 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4343 public static bool IsWhiteSpace ( char c )
4444 {
45- return c == ' ' || ( c >= '\x0009 ' && c <= '\x000d ' ) || c == '\x00a0 ' || c == '\x0085 ' ;
45+ return c == ' ' || ( c >= '\x0009 ' && c <= '\x000d ' ) || c == '\x00a0 ' || c == '\x0085 ' || c == TypeConstants . NonWidthWhiteSpace ;
4646 }
4747
4848 public static void WriteString ( TextWriter writer , string value )
Original file line number Diff line number Diff line change 1- using NUnit . Framework ;
1+ using System . IO ;
2+ using Northwind . Common . DataModel ;
3+ using NUnit . Framework ;
4+ using ServiceStack . Text . Json ;
25
36namespace ServiceStack . Text . Tests . Issues
47{
@@ -20,5 +23,27 @@ public void Does_deserialize_empty_string_to_object()
2023 var obj = json . FromJson < object > ( ) ;
2124 Assert . That ( obj , Is . EqualTo ( "" ) ) ;
2225 }
26+
27+ public class ObjectEmptyStringTest
28+ {
29+ public object Name { get ; set ; }
30+ }
31+
32+ [ Test ]
33+ public void Does_serialize_property_Empty_String ( )
34+ {
35+ JS . Configure ( ) ;
36+ var dto = new ObjectEmptyStringTest { Name = "" } ;
37+ var json = dto . ToJson ( ) ;
38+
39+ var fromJson = json . FromJson < ObjectEmptyStringTest > ( ) ;
40+ Assert . That ( fromJson . Name , Is . EqualTo ( dto . Name ) ) ;
41+
42+ var utf8 = json . ToUtf8Bytes ( ) ;
43+ var ms = new MemoryStream ( utf8 ) ;
44+ var fromMs = JsonSerializer . DeserializeFromStream < ObjectEmptyStringTest > ( ms ) ;
45+ Assert . That ( fromMs . Name , Is . EqualTo ( dto . Name ) ) ;
46+ JS . UnConfigure ( ) ;
47+ }
2348 }
2449}
You can’t perform that action at this time.
0 commit comments