forked from microsoft/kiota-serialization-json-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_parse_node_factory.go
35 lines (29 loc) · 1.02 KB
/
json_parse_node_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"
)
// JsonParseNodeFactory is a ParseNodeFactory implementation for JSON
type JsonParseNodeFactory struct {
}
// Creates a new JsonParseNodeFactory
func NewJsonParseNodeFactory() *JsonParseNodeFactory {
return &JsonParseNodeFactory{}
}
// GetValidContentType returns the content type this factory's parse nodes can deserialize.
func (f *JsonParseNodeFactory) GetValidContentType() (string, error) {
return "application/json", nil
}
// GetRootParseNode return a new ParseNode instance that is the root of the content
func (f *JsonParseNodeFactory) GetRootParseNode(contentType string, content []byte) (absser.ParseNode, 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 NewJsonParseNode(content)
}
}