Skip to content

Commit

Permalink
Merge pull request #54 from Deathstr0ke1/master
Browse files Browse the repository at this point in the history
Explicitly convert inMediaType json to outMediaType yaml
  • Loading branch information
jmhbnz authored May 19, 2024
2 parents 4addb26 + c7cfb3d commit 4c462f6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ func Convert(codecs serializer.CodecFactory, inMediaType, outMediaType string, i
if outMediaType == JsonMediaType {
encoded = append(encoded, '\n')
}
} else if inMediaType == JsonMediaType && outMediaType == YamlMediaType {
val := map[string]interface{}{}
if err := json.Unmarshal(in, &val); err != nil {
return nil, nil, fmt.Errorf("error decoding from %s: %s", inMediaType, err)
}
encoded, err = yaml.Marshal(val)
if err != nil {
return nil, nil, fmt.Errorf("error encoding from %s: %s", outMediaType, err)
}
} else {
inCodec, err := newCodec(codecs, typeMeta, inMediaType)
if err != nil {
Expand Down

0 comments on commit 4c462f6

Please sign in to comment.