Commit graph

88 commits

Author SHA1 Message Date
Shuhei Kitagawa
7901e98f54
Support non string map keys (#756)
* fix map keys misencoding to string

* Add unit tests

* Add tests for decoder with unconventional map keys

---------

Co-authored-by: Zsolt Herczeg <herczegzsolt@herczegzsolt.hu>
2025-11-29 11:37:53 +09:00
Patrick Gerber
52dacb84f3
Update custom marshaler and unmarshaler to accept context (#745)
* feat: Update custom marshaler and unmarshaler to accept context

* Add tests for custom marshaler and unmarshaler with context
2025-05-29 14:13:29 +09:00
Masaaki Goshima
c430438700
Support omitzero (#729) 2025-05-22 18:30:01 +09:00
Shuhei Kitagawa
cd70dcffaa
Treat output from TextMarshaler as string (#698) 2025-05-05 23:27:26 +09:00
Bartlomiej Plotka
d1e3460292
chore: clarify omitempty behaviour. (#696)
Fixes 0-1 steps from https://github.com/goccy/go-yaml/issues/695.

Signed-off-by: bwplotka <bwplotka@gmail.com>
2025-04-16 23:15:32 +09:00
Bartlomiej Plotka
ee37df774b
feat: add global OmitEmpty encoding option (#691)
Thanks for an amazing project! Go ecosystem struggle (e.g. https://github.com/GoogleCloudPlatform/prometheus-engine/issues/1629)
with 3P types that lack a good marshalling practices. Many project have
config structs only designed for parsing. See https://github.com/goccy/go-yaml/issues/306
for the detailed motivation.

Fixes: https://github.com/goccy/go-yaml/issues/306

The feature mechanism is simple -- we ignore struct tag setting for omitempty.
We assume it's always 'omitempty' if yaml.OmitEmpty() setting is set.

Signed-off-by: bwplotka <bwplotka@gmail.com>
2025-04-11 19:13:15 +09:00
dorencambia
96713633e1
encodeMap() error handling and TestEncoder_UnmarshallableTypes() (#674)
* encodeMap() error handling and TestEncoder_UnmarshallableTypes()

* more TestEncoder_UnmarshallableTypes test cases
2025-03-07 10:45:33 +09:00
Shuhei Kitagawa
944206aba5
Add AutoInt option (#671) 2025-02-25 22:44:58 +09:00
Masaaki Goshima
89a66008de
Fix encoding of string that contains "- " (#657)
* fix encoding of string that contains "- "

* fix test case
2025-02-15 12:00:39 +09:00
Yusuke Kuoka
13e918a61d
Make UseSingleQuote compliant with the YAML spec (#647)
* Make UseSingleQuote compliant with the YAML spec

* Make it self-explanatory
2025-02-12 14:22:42 +09:00
Lars Stegman
81dbf2619c
Fix toString for TagNode (#633)
* fix tag encode in mapping

* support tag with map value

* fix TagNode toString

* Undo go mod change

* Undo editor auto change

* fix preceding space TagNode.String()

* fix merge

* fix lint

* improve tests

* fix anchor before tag

---------

Co-authored-by: Rangel Reale <rangelspam@gmail.com>
2025-02-04 14:25:25 +09:00
Shuhei Kitagawa
c8cc5c583f
Fix indentation for raw string newlines (#625)
https://github.com/goccy/go-yaml/issues/292
2025-01-31 10:27:06 +09:00
Masaaki Goshima
9cbf5d4217
Fix encoding of anchor and alias (#605)
* fix encoding of anchor and alias

* fix alias

* fix lint error
2024-12-23 10:25:20 +09:00
Masaaki Goshima
beec790be2
fix encoding with map key contains colon character (#604) 2024-12-22 20:28:28 +09:00
Oleksandr Redko
7601ad3fe8
Fix displaying testable example on pkg.go.dev (#587) 2024-12-13 09:27:52 +09:00
Oleksandr Redko
342293d734
Replace fmt.Sprint with faster alternatives (#555) 2024-12-13 00:31:35 +09:00
Shuhei Kitagawa
83d3e55c24
Fix quotation for timestamps (#515)
Co-authored-by: shuheiktgw <s-kitagawa@mercari.com>
2024-12-12 18:05:46 +09:00
Masaaki Goshima
6b0c68e62a
Fix parsing of document and string (#513)
* fix invalid test case
* fix parsing of document
* fix validation
2024-11-09 13:00:12 +09:00
Shuhei Kitagawa
8ad318cffc
Add lint job to CI (#477) 2024-10-28 11:31:15 +09:00
Ken’ichiro Oyama
237df0ef1c
Quote is required even if it begins with backquote. (#440) 2024-07-16 19:39:25 +09:00
Morris Kelly
b5f63d50d0
Fix decoding of scientific notation (#463)
* Fix scientific notation decoding and add encoding test cases

* Deal with ints and uints

* Add coverage for uint changes
2024-07-16 19:38:06 +09:00
ozraru
680ea24289
Fix handle of space at start or last (#376) 2023-09-14 12:36:25 +09:00
Kenta Mori
f5c5711fc6
fix: skip encoding an inline field if it is null (#386) 2023-09-13 17:17:47 +09:00
Masaaki Goshima
4052b059bc
Supports dynamically switch encode and decode processing for a given type (#368) 2023-04-02 10:50:03 +09:00
Martin Sucha
3ca6a75302
Don't trim all space characters in SequenceNode.blockStyleString (#361)
* Don't trim all space characters in SequenceNode.blockStyleString

This fixes https://github.com/goccy/go-yaml/issues/356.
The code would have removed more spaces than it added.

A better solution long-term would probably be to add a specialized
method to StringNode to not add the prefix in the first place.

* Add issue 356 test case for block with first empty line

The indentation level in a block scalar is determined by the first
non-empty line.
2023-03-22 08:31:12 +09:00
Yusuke Kuoka
f3319d6c80
Quote YAML 1.1 bools at encoding time for compatibility with other legacy parsers (#354) 2023-03-14 15:24:34 +09:00
Masaaki Goshima
45bdea2a27
fix custom marshaler (#333) 2022-12-19 13:48:03 +09:00
Masaaki Goshima
bc437e1a54
Merge pull request #270 from igorpeshansky/fix-flow-mode-quotes
Quote strings with special characters in flow mode.
2022-10-26 17:43:50 +09:00
zoncoen
548aa0527d
fix: insert a separator between each encoded document
Fix the behavior as the comment.
2022-10-25 01:13:00 +09:00
Julien Rische
66e8faa858 Fix large literals type inference on 32 bits
Some tests are failing because some large literal integers are meant to
be stored on 64 bits, but are stored on 32 on 32 bits architectures.
This causes the value to overflow.

This commit fixes this issue by using explicit int64 typing.

Signed-off-by: Julien Rische <jrische@redhat.com>
2022-06-07 12:40:23 +02:00
Masaaki Goshima
d6e2aed126
Fix encoding of BytesMarshaler type 2022-01-11 18:15:12 +09:00
Masaaki Goshima
9bcbd0aebc
Fix encoding of sequence with multiline string 2022-01-11 17:43:12 +09:00
Igor Peshansky
450c46a149 Quote strings with special characters in flow mode. 2021-11-23 00:02:43 -05:00
Viktor Stanchev
e8c5eef27a
add UseSingleQuote option 2021-11-06 02:53:14 +00:00
Quentin Smith
02069998ec Merge remote-tracking branch 'upstream/master' into duration 2021-08-24 16:44:27 -04:00
Quentin Smith
ad99694948 Fix encoding of large floats
An extra ".0" was getting appended when the value of the float was a
power of 10.
2021-08-16 16:31:14 -04:00
Quentin Smith
70a646fc95 Add test for Duration encoding in JSON mode 2021-08-12 14:56:40 -04:00
Quentin Smith
adc9a196b2 Encode and decode time.Duration fields (#201)
This uses `time.ParseDuration` and `time.Duration.String`, and is
compatible with gopkg.in/yaml's encoding.
2021-08-11 15:07:04 -04:00
Viktor Stanchev
d51bcc85fc
fix bug in encoding nested sequences with IndentSequence 2021-08-09 14:06:30 +00:00
Masaaki Goshima
c14dac734e Rename MarshalWithContext and UnmarshalWithContext 2021-07-19 19:01:49 +09:00
Ryo Kitagawa
036fc04cd4 Merge branch 'master' into support-defined-type-key 2021-06-30 14:34:11 +09:00
Florian Rey
4768d503b1 Support sequence indentation 2021-06-29 16:35:54 +02:00
Ryo Kitagawa
f3614c79b6 Support to encode map which has defined type key 2021-06-26 20:38:11 +09:00
Masaaki Goshima
0031d860a6 Fix encoding of float value 2021-03-01 16:17:23 +09:00
Masaaki Goshima
0eb1e3de9f Support to encode ast.Node directly 2021-03-01 13:45:44 +09:00
Masaaki Goshima
eb2d4ab35f Fix test case 2020-11-19 17:59:14 +09:00
Masaaki Goshima
7ea1684d4c
Merge pull request #164 from cmaster11/multiline-block-fix
Add `UseLiteralStyleIfMultiLine` option
2020-11-19 17:55:17 +09:00
Alberto Marchetti
6a3fb60539 * Addressed PR comments 2020-11-19 10:15:56 +02:00
Alberto Marchetti
b2c149ae52 Merge remote-tracking branch 'origin/multiline-block-fix' into multiline-block-fix
# Conflicts:
#	encode.go
2020-11-18 07:36:24 +02:00
Alberto Marchetti
47f32d7bb0 * Addressed PR comments
* Added support for encode options in encoder test
2020-11-18 07:35:17 +02:00