Skip to content

Add YAML deserialization and serialization support - #173

Open
AdamMagued wants to merge 1 commit into
stretchr:masterfrom
AdamMagued:add-yaml-support
Open

AdamMagued wants to merge 1 commit into
stretchr:masterfrom
AdamMagued:add-yaml-support

Conversation

@AdamMagued

Copy link
Copy Markdown

Summary

Fixes #135

Objx provides conversion constructors and serialization methods for JSON (FromJSON, MustFromJSON, FromJSONSlice, MustFromJSONSlice, Map.JSON, Map.MustJSON), Base64, and URL Query strings, but lacked built-in support for YAML documents. Users working with YAML configurations had to manually parse YAML documents outside objx.

This PR adds YAML deserialization and serialization support:

  • FromYAML(yamlString string) (Map, error) and MustFromYAML(yamlString string) Map
  • FromYAMLSlice(yamlString string) ([]Map, error) and MustFromYAMLSlice(yamlString string) []Map
  • Map.YAML() (string, error) and Map.MustYAML() string
  • Convenient aliases FromYaml, MustFromYaml, FromYamlSlice, MustFromYamlSlice, Map.Yaml, and Map.MustYaml
  • Support for map[string]interface{} and []map[interface{}]interface{} in recursive cleanUp
  • Robust error handling recovering from unsupported-type panics during YAML marshaling/unmarshaling

Verification

  • Added regression tests in map_test.go verifying FromYAML, MustFromYAML, aliases, error handling, nested YAML mappings, and top-level YAML slices.
  • Added tests in conversions_test.go verifying Map.YAML(), MustYAML(), aliases, nested maps with interface keys, and error conditions.
  • Ran test suite with race detector: go test -race ./... (100% passed).
  • Verified code style and linting: gofmt -d -s *.go and go vet ./... (clean output).

Implement FromYAML, MustFromYAML, FromYAMLSlice, MustFromYAMLSlice, and Map.YAML/MustYAML methods (with FromYaml and Map.Yaml aliases) using gopkg.in/yaml.v3. Also extend cleanUp to handle nested map[string]interface{} and []map[interface{}]interface{}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FromYaml ?

1 participant