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 JsonApiDotNetCore . Models ;
3
3
4
4
namespace JsonApiDotNetCoreExample . Models
@@ -25,12 +25,12 @@ public TodoItem()
25
25
[ Attr ( "achieved-date" , isFilterable : false , isSortable : false ) ]
26
26
public DateTime ? AchievedDate { get ; set ; }
27
27
28
-
29
28
[ Attr ( "updated-date" ) ]
30
29
public DateTime ? UpdatedDate { get ; set ; }
31
30
32
-
33
-
31
+ [ Attr ( "offset-date" ) ]
32
+ public DateTimeOffset ? OffsetDate { get ; set ; }
33
+
34
34
public int ? OwnerId { get ; set ; }
35
35
public int ? AssigneeId { get ; set ; }
36
36
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 @@ -404,6 +404,7 @@ public async Task Can_Post_TodoItem()
404
404
_context . SaveChanges ( ) ;
405
405
406
406
var todoItem = _todoItemFaker . Generate ( ) ;
407
+ var nowOffset = new DateTimeOffset ( ) ;
407
408
var content = new
408
409
{
409
410
data = new
@@ -413,7 +414,8 @@ public async Task Can_Post_TodoItem()
413
414
{
414
415
{ "description" , todoItem . Description } ,
415
416
{ "ordinal" , todoItem . Ordinal } ,
416
- { "created-date" , todoItem . CreatedDate }
417
+ { "created-date" , todoItem . CreatedDate } ,
418
+ { "offset-date" , nowOffset }
417
419
} ,
418
420
relationships = new
419
421
{
@@ -446,6 +448,7 @@ public async Task Can_Post_TodoItem()
446
448
Assert . Equal ( HttpStatusCode . Created , response . StatusCode ) ;
447
449
Assert . Equal ( todoItem . Description , deserializedBody . Description ) ;
448
450
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" ) ) ;
449
452
Assert . Null ( deserializedBody . AchievedDate ) ;
450
453
}
451
454
You can’t perform that action at this time.
0 commit comments