This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
src/ServiceStack.Text/Common
tests/ServiceStack.Text.Tests Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,9 @@ public static Type ParseType(string assemblyQualifiedName)
6363
6464 public static object TryParseEnum ( Type enumType , string str )
6565 {
66+ if ( str == null )
67+ return null ;
68+
6669 if ( JsConfig . EmitLowercaseUnderscoreNames )
6770 {
6871 string [ ] names = Enum . GetNames ( enumType ) ;
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3+ using System . Runtime . Serialization ;
34using NUnit . Framework ;
45
56namespace ServiceStack . Text . Tests
@@ -157,6 +158,25 @@ public void Can_serialize_different_enum_styles()
157158 Assert . That ( "Underscore_Words" . FromJson < EnumStyles > ( ) , Is . EqualTo ( EnumStyles . Underscore_Words ) ) ;
158159 }
159160 }
161+
162+ [ DataContract ]
163+ public class NullableEnum
164+ {
165+ [ DataMember ( Name = "myEnum" ) ]
166+ public EnumWithoutFlags ? MyEnum { get ; set ; }
167+ }
168+
169+ [ Test ]
170+ public void Can_deserialize_null_Nullable_Enum ( )
171+ {
172+ JsConfig . ThrowOnDeserializationError = true ;
173+ string json = @"{""myEnum"":null}" ;
174+ var o = json . FromJson < NullableEnum > ( ) ;
175+ Assert . That ( o . MyEnum , Is . Null ) ;
176+
177+ JsConfig . Reset ( ) ;
178+ }
179+
160180 }
161181}
162182
You can’t perform that action at this time.
0 commit comments