diff --git a/ion/unmarshal.go b/ion/unmarshal.go index c365776..2d4908c 100644 --- a/ion/unmarshal.go +++ b/ion/unmarshal.go @@ -506,13 +506,20 @@ func (d *Decoder) decodeTimestampTo(v reflect.Value) error { switch v.Kind() { case reflect.Struct: - if v.Type() == timestampType { + switch v.Type() { + case timestampType: if val != nil { v.Set(reflect.ValueOf(*val)) } return d.attachAnnotations(v) + case nativeTimeType: + if val != nil { + v.Set(reflect.ValueOf((*val).dateTime)) + } + return d.attachAnnotations(v) + default: + return d.decodeToStructWithAnnotation(v, timestampType.Kind()) } - return d.decodeToStructWithAnnotation(v, timestampType.Kind()) case reflect.Interface: if v.NumMethod() == 0 { diff --git a/ion/unmarshal_test.go b/ion/unmarshal_test.go index a5f10af..7d81d6a 100644 --- a/ion/unmarshal_test.go +++ b/ion/unmarshal_test.go @@ -422,10 +422,19 @@ func TestDecodeTimestampTo(t *testing.T) { t.Run(str, func(t *testing.T) { d := NewDecoder(NewReaderString(str)) - var val Timestamp - require.NoError(t, d.DecodeTo(&val)) + var timestampVal Timestamp + require.NoError(t, d.DecodeTo(×tampVal)) - assert.True(t, val.Equal(eval), "expected %v, got %v", eval, val) + assert.True(t, timestampVal.Equal(eval), "expected %v, got %v", eval, timestampVal) + }) + + t.Run(str, func(t *testing.T) { + d := NewDecoder(NewReaderString(str)) + + var timeVal time.Time + require.NoError(t, d.DecodeTo(&timeVal)) + + assert.True(t, timeVal.Equal(eval.dateTime), "expected %v, got %v", eval.dateTime, timeVal) }) } test("null", Timestamp{})