Add Example tests and fix raw value extraction for boolean types

Add two godoc Example tests:
- ExampleDecoder_EnableUnmarshalerInterface_dynamicConfig: shows dynamic
  unmarshaling based on a type field
- ExampleDecoder_EnableUnmarshalerInterface_rawMessage: demonstrates
  RawMessage usage for deferred parsing

Fix handleKeyValuesUnmarshaler to handle values where Raw.Length == 0
(like boolean types) by using value.Data as fallback.
This commit is contained in:
Claude
2026-01-16 13:36:42 +00:00
parent 9f1bb6c97d
commit 6c995ec13e
2 changed files with 135 additions and 2 deletions
+9 -2
View File
@@ -729,8 +729,15 @@ func (d *decoder) handleKeyValuesUnmarshaler(u unstable.Unmarshaler) (reflect.Va
// Get the raw value bytes
value := expr.Value()
if value != nil {
raw := d.p.Raw(value.Raw)
buf = append(buf, raw...)
if value.Raw.Length > 0 {
// Use raw bytes from the original document
raw := d.p.Raw(value.Raw)
buf = append(buf, raw...)
} else {
// Some value types (like Bool) don't have Raw set,
// use Data which contains the value representation
buf = append(buf, value.Data...)
}
}
buf = append(buf, '\n')
}