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)
94
94
return primitiveType ;
95
95
96
96
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 ( ) ;
98
100
99
101
return Serializer . UnescapeString ( strType ) . Value ( ) ;
100
102
}
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ public static class JsonUtils
42
42
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
43
43
public static bool IsWhiteSpace ( char c )
44
44
{
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 ;
46
46
}
47
47
48
48
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 ;
2
5
3
6
namespace ServiceStack . Text . Tests . Issues
4
7
{
@@ -20,5 +23,27 @@ public void Does_deserialize_empty_string_to_object()
20
23
var obj = json . FromJson < object > ( ) ;
21
24
Assert . That ( obj , Is . EqualTo ( "" ) ) ;
22
25
}
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
+ }
23
48
}
24
49
}
You can’t perform that action at this time.
0 commit comments