File tree Expand file tree Collapse file tree 3 files changed +15
-7
lines changed
Examples/JsonApiDotNetCoreExample/Models
JsonApiDotNetCore/Serialization
test/JsonApiDotNetCoreExampleTests/Acceptance Expand file tree Collapse file tree 3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 1- using System ;
1+ using System ;
22using JsonApiDotNetCore . Models ;
33
44namespace JsonApiDotNetCoreExample . Models
@@ -25,12 +25,12 @@ public TodoItem()
2525 [ Attr ( "achieved-date" , isFilterable : false , isSortable : false ) ]
2626 public DateTime ? AchievedDate { get ; set ; }
2727
28-
2928 [ Attr ( "updated-date" ) ]
3029 public DateTime ? UpdatedDate { get ; set ; }
3130
32-
33-
31+ [ Attr ( "offset-date" ) ]
32+ public DateTimeOffset ? OffsetDate { get ; set ; }
33+
3434 public int ? OwnerId { get ; set ; }
3535 public int ? AssigneeId { get ; set ; }
3636 public Guid ? CollectionId { get ; set ; }
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
34using System . Linq ;
45using System . Reflection ;
56using JsonApiDotNetCore . Extensions ;
@@ -36,8 +37,12 @@ public object Deserialize(string requestBody)
3637 {
3738 try
3839 {
39- var bodyJToken = JToken . Parse ( requestBody ) ;
40-
40+ JToken bodyJToken ;
41+ using ( JsonReader jsonReader = new JsonTextReader ( new StringReader ( requestBody ) ) )
42+ {
43+ jsonReader . DateParseHandling = DateParseHandling . None ;
44+ bodyJToken = JToken . Load ( jsonReader ) ;
45+ }
4146 if ( RequestIsOperation ( bodyJToken ) )
4247 {
4348 _jsonApiContext . IsBulkOperationRequest = true ;
Original file line number Diff line number Diff line change @@ -404,6 +404,7 @@ public async Task Can_Post_TodoItem()
404404 _context . SaveChanges ( ) ;
405405
406406 var todoItem = _todoItemFaker . Generate ( ) ;
407+ var nowOffset = new DateTimeOffset ( ) ;
407408 var content = new
408409 {
409410 data = new
@@ -413,7 +414,8 @@ public async Task Can_Post_TodoItem()
413414 {
414415 { "description" , todoItem . Description } ,
415416 { "ordinal" , todoItem . Ordinal } ,
416- { "created-date" , todoItem . CreatedDate }
417+ { "created-date" , todoItem . CreatedDate } ,
418+ { "offset-date" , nowOffset }
417419 } ,
418420 relationships = new
419421 {
@@ -446,6 +448,7 @@ public async Task Can_Post_TodoItem()
446448 Assert . Equal ( HttpStatusCode . Created , response . StatusCode ) ;
447449 Assert . Equal ( todoItem . Description , deserializedBody . Description ) ;
448450 Assert . Equal ( todoItem . CreatedDate . ToString ( "G" ) , deserializedBody . CreatedDate . ToString ( "G" ) ) ;
451+ Assert . Equal ( nowOffset . ToString ( "yyyy-MM-ddTHH:mm:ssK" ) , deserializedBody . OffsetDate ? . ToString ( "yyyy-MM-ddTHH:mm:ssK" ) ) ;
449452 Assert . Null ( deserializedBody . AchievedDate ) ;
450453 }
451454
You can’t perform that action at this time.
0 commit comments