File tree 3 files changed +15
-7
lines changed
Examples/JsonApiDotNetCoreExample/Models
JsonApiDotNetCore/Serialization
test/JsonApiDotNetCoreExampleTests/Acceptance
3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using JsonApiDotNetCore . Models ;
4
4
@@ -26,12 +26,12 @@ public TodoItem()
26
26
[ Attr ( "achieved-date" , isFilterable : false , isSortable : false ) ]
27
27
public DateTime ? AchievedDate { get ; set ; }
28
28
29
-
30
29
[ Attr ( "updated-date" ) ]
31
30
public DateTime ? UpdatedDate { get ; set ; }
32
31
33
-
34
-
32
+ [ Attr ( "offset-date" ) ]
33
+ public DateTimeOffset ? OffsetDate { get ; set ; }
34
+
35
35
public int ? OwnerId { get ; set ; }
36
36
public int ? AssigneeId { get ; set ; }
37
37
public Guid ? CollectionId { get ; set ; }
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . IO ;
3
4
using System . Linq ;
4
5
using System . Reflection ;
5
6
using JsonApiDotNetCore . Extensions ;
@@ -36,8 +37,12 @@ public object Deserialize(string requestBody)
36
37
{
37
38
try
38
39
{
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
+ }
41
46
if ( RequestIsOperation ( bodyJToken ) )
42
47
{
43
48
_jsonApiContext . IsBulkOperationRequest = true ;
Original file line number Diff line number Diff line change @@ -452,6 +452,7 @@ public async Task Can_Post_TodoItem()
452
452
_context . SaveChanges ( ) ;
453
453
454
454
var todoItem = _todoItemFaker . Generate ( ) ;
455
+ var nowOffset = new DateTimeOffset ( ) ;
455
456
var content = new
456
457
{
457
458
data = new
@@ -461,7 +462,8 @@ public async Task Can_Post_TodoItem()
461
462
{
462
463
{ "description" , todoItem . Description } ,
463
464
{ "ordinal" , todoItem . Ordinal } ,
464
- { "created-date" , todoItem . CreatedDate }
465
+ { "created-date" , todoItem . CreatedDate } ,
466
+ { "offset-date" , nowOffset }
465
467
} ,
466
468
relationships = new
467
469
{
@@ -494,6 +496,7 @@ public async Task Can_Post_TodoItem()
494
496
Assert . Equal ( HttpStatusCode . Created , response . StatusCode ) ;
495
497
Assert . Equal ( todoItem . Description , deserializedBody . Description ) ;
496
498
Assert . Equal ( todoItem . CreatedDate . ToString ( "G" ) , deserializedBody . CreatedDate . ToString ( "G" ) ) ;
499
+ Assert . Equal ( nowOffset . ToString ( "yyyy-MM-ddTHH:mm:ssK" ) , deserializedBody . OffsetDate ? . ToString ( "yyyy-MM-ddTHH:mm:ssK" ) ) ;
497
500
Assert . Null ( deserializedBody . AchievedDate ) ;
498
501
}
499
502
You can’t perform that action at this time.
0 commit comments