Skip to content

Commit 9eb4a95

Browse files
committed
merge conflict
1 parent 9387e0d commit 9eb4a95

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

models_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ type TimestampModel struct {
3636
}
3737

3838
type WithNullableAttrs struct {
39-
ID int `jsonapi:"primary,with-nullables"`
40-
Name string `jsonapi:"attr,name"`
41-
IntTime NullableAttr[time.Time] `jsonapi:"attr,int_time,omitempty"`
42-
RFC3339Time NullableAttr[time.Time] `jsonapi:"attr,rfc3339_time,rfc3339,omitempty"`
43-
ISO8601Time NullableAttr[time.Time] `jsonapi:"attr,iso8601_time,iso8601,omitempty"`
44-
Bool NullableAttr[bool] `jsonapi:"attr,bool,omitempty"`
39+
ID int `jsonapi:"primary,with-nullables"`
40+
Name string `jsonapi:"attr,name"`
41+
IntTime NullableAttr[time.Time] `jsonapi:"attr,int_time,omitempty"`
42+
RFC3339Time NullableAttr[time.Time] `jsonapi:"attr,rfc3339_time,rfc3339,omitempty"`
43+
ISO8601Time NullableAttr[time.Time] `jsonapi:"attr,iso8601_time,iso8601,omitempty"`
44+
Bool NullableAttr[bool] `jsonapi:"attr,bool,omitempty"`
4545
NullableComment NullableRelationship[*Comment] `jsonapi:"relation,nullable_comment,omitempty"`
4646
}
4747

request.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ func unmarshalNode(data *Node, model reflect.Value, included *map[string]*includ
487487
relationship := new(RelationshipOneNode)
488488

489489
buf := bytes.NewBuffer(nil)
490-
491490
relDataStr := data.Relationships[args[1]]
492491
json.NewEncoder(buf).Encode(relDataStr)
493492

@@ -498,7 +497,7 @@ func unmarshalNode(data *Node, model reflect.Value, included *map[string]*includ
498497
// this indicates disassociating the relationship
499498
isExplicitNull = true
500499
} else if relationshipDecodeErr != nil {
501-
er = fmt.Errorf("decode err %v\n", relationshipDecodeErr)
500+
er = fmt.Errorf("Could not unmarshal json: %w", relationshipDecodeErr)
502501
}
503502

504503
// This will hold either the value of the choice type model or the actual
@@ -512,7 +511,6 @@ func unmarshalNode(data *Node, model reflect.Value, included *map[string]*includ
512511
m = reflect.New(fieldValue.Type().Elem().Elem())
513512
}
514513
}
515-
516514
/*
517515
http://jsonapi.org/format/#document-resource-object-relationships
518516
http://jsonapi.org/format/#document-resource-object-linkage
@@ -522,7 +520,7 @@ func unmarshalNode(data *Node, model reflect.Value, included *map[string]*includ
522520
if relationship.Data == nil {
523521
// Explicit null supplied for the field value
524522
// If a nullable relationship we set the field value to a map with a single entry
525-
if isExplicitNull {
523+
if isExplicitNull && strings.HasPrefix(fieldType.Type.Name(), "NullableRelationship[") {
526524
fieldValue.Set(reflect.MakeMapWithSize(fieldValue.Type(), 1))
527525
fieldValue.SetMapIndex(reflect.ValueOf(false), m)
528526
}
@@ -536,7 +534,6 @@ func unmarshalNode(data *Node, model reflect.Value, included *map[string]*includ
536534
continue
537535
}
538536

539-
540537
// Check if the item in the relationship was already processed elsewhere. Avoids potential infinite recursive loops
541538
// caused by circular references between included relationships (two included items include one another)
542539
includedKey := fmt.Sprintf("%s,%s", relationship.Data.Type, relationship.Data.ID)

0 commit comments

Comments
 (0)