ccoVeille commented on PR #3786:
URL: https://github.com/apache/dubbo-go/pull/3786#issuecomment-6559729690

   > One behaviour change in rc.7 worth noting\nconstructTimestamp now also 
handles string targets\n(internal/libyaml/constructor.go:416-418, case 
reflect.String → out.SetString(n.Value)).\n\nMeasured on a minimal program (t: 
2020-01-01 into struct{ T string }):\n\nrc.6: err=yaml: construct errors: line 
1: cannot construct !!timestamp `2020-01-01` into string  T=\"\"\nrc.7: 
err=\u003Cnil>  T=\"2020-01-01\"\nSo this is a real behaviour change: 
previously such a document failed with a\nconstruct error (and left the field 
empty), now it decodes to the raw text. It\nis relevant to dubbo-go's config 
structs, which mix string and typed fields —\nno such document surfaced in our 
test runs, so nothing changed for us there. I\ndid not audit every fixture by 
hand, so treat that as \"tests are green\" rather\nthan a proof of absence.
   
   About this 👆
   
   Thanks for bringing this up. This is an intentional change introduced in 
v4.0.0-rc.7, which resolves issue https://github.com/yaml/go-yam/issue/376 via 
pull request https://github.com/yaml/go-yam/pull/379.
   
   Technical Context
   When unmarshaling an unquoted scalar matching a date format (such as 
2020-01-01), the YAML parser implicitly resolves it to the !!timestamp tag. 
Prior to v4.0.0-rc.7, constructTimestamp in internal/libyaml/constructor.go 
only handled targets expecting timestamp/time representations and rejected 
target Go fields of type reflect.String with a construct error.
   In rc.7, the case reflect.String: block was added to constructTimestamp 
(out.SetString(n.Value)) to allow timestamp-tagged nodes to decode into a Go 
string by extracting the raw scalar value.
   Why this change was made
    * Decoder Consistency: Other scalar types (integers, booleans, floats) 
already supported decoding into a Go string field. Restricting timestamp 
scalars from decoding into string created an inconsistent decoding behavior 
across scalar types.
    * Go Type Flexibility: In Go unmarshalers, string fields act as general 
textual targets. The decoder should not fail when decoding valid scalar data 
into a string target.
   
   This behavior is normal and expected for v4. It fixes a decoding limitation 
without introducing breaking changes to existing valid unmarshals.
   
   But yes, it's a change somehow
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to