forked from microsoft/kiota-serialization-json-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_serialization_writer_factory.go
35 lines (29 loc) · 1.18 KB
/
json_serialization_writer_factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package jsonserialization
import (
"errors"
absser "github.com/microsoft/kiota-abstractions-go/serialization"
)
// JsonSerializationWriterFactory implements SerializationWriterFactory for JSON.
type JsonSerializationWriterFactory struct {
}
// NewJsonSerializationWriterFactory creates a new instance of the JsonSerializationWriterFactory.
func NewJsonSerializationWriterFactory() *JsonSerializationWriterFactory {
return &JsonSerializationWriterFactory{}
}
// GetValidContentType returns the valid content type for the SerializationWriterFactoryRegistry
func (f *JsonSerializationWriterFactory) GetValidContentType() (string, error) {
return "application/json", nil
}
// GetSerializationWriter returns the relevant SerializationWriter instance for the given content type
func (f *JsonSerializationWriterFactory) GetSerializationWriter(contentType string) (absser.SerializationWriter, error) {
validType, err := f.GetValidContentType()
if err != nil {
return nil, err
} else if contentType == "" {
return nil, errors.New("contentType is empty")
} else if contentType != validType {
return nil, errors.New("contentType is not valid")
} else {
return NewJsonSerializationWriter(), nil
}
}