Skip to content

Commit 4c462f6

Browse files
authored
Merge pull request #54 from Deathstr0ke1/master
Explicitly convert inMediaType json to outMediaType yaml
2 parents 4addb26 + c7cfb3d commit 4c462f6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/encoding/encoding.go

+9
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ func Convert(codecs serializer.CodecFactory, inMediaType, outMediaType string, i
9595
if outMediaType == JsonMediaType {
9696
encoded = append(encoded, '\n')
9797
}
98+
} else if inMediaType == JsonMediaType && outMediaType == YamlMediaType {
99+
val := map[string]interface{}{}
100+
if err := json.Unmarshal(in, &val); err != nil {
101+
return nil, nil, fmt.Errorf("error decoding from %s: %s", inMediaType, err)
102+
}
103+
encoded, err = yaml.Marshal(val)
104+
if err != nil {
105+
return nil, nil, fmt.Errorf("error encoding from %s: %s", outMediaType, err)
106+
}
98107
} else {
99108
inCodec, err := newCodec(codecs, typeMeta, inMediaType)
100109
if err != nil {

0 commit comments

Comments
 (0)