Skip to content

Commit

Permalink
Fixed incorrect handling of default nullable values.
Browse files Browse the repository at this point in the history
  • Loading branch information
edgefox committed Mar 25, 2015
1 parent 5c8e29f commit 61ed6d7
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ type RecordSchema struct {
Doc string `json:"doc,omitempty"`
Aliases []string `json:"aliases,omitempty"`
Properties map[string]string
Fields []*SchemaField `json:"fields,omitempty"`
Fields []*SchemaField `json:"fields"`
}

func (this *RecordSchema) String() string {
Expand All @@ -335,7 +335,7 @@ func (this *RecordSchema) MarshalJSON() ([]byte, error) {
Name string `json:"name,omitempty"`
Doc string `json:"doc,omitempty"`
Aliases []string `json:"aliases,omitempty"`
Fields []*SchemaField `json:"fields,omitempty"`
Fields []*SchemaField `json:"fields"`
}{
Type: "record",
Namespace: this.Namespace,
Expand Down Expand Up @@ -407,10 +407,38 @@ func (this *RecursiveSchema) MarshalJSON() ([]byte, error) {
type SchemaField struct {
Name string `json:"name,omitempty"`
Doc string `json:"doc,omitempty"`
Default interface{} `json:"default,omitempty"`
Default interface{} `json:"default"`
Type Schema `json:"type,omitempty"`
}

func (this *SchemaField) MarshalJSON() ([]byte, error) {
if this.Type.Type() == Null || (this.Type.Type() == Union && this.Type.(*UnionSchema).Types[0].Type() == Null) {
return json.Marshal(struct {
Name string `json:"name,omitempty"`
Doc string `json:"doc,omitempty"`
Default interface{} `json:"default"`
Type Schema `json:"type,omitempty"`
}{
Name: this.Name,
Doc: this.Doc,
Default: this.Default,
Type: this.Type,
})
} else {
return json.Marshal(struct {
Name string `json:"name,omitempty"`
Doc string `json:"doc,omitempty"`
Default interface{} `json:"default,omitempty"`
Type Schema `json:"type,omitempty"`
}{
Name: this.Name,
Doc: this.Doc,
Default: this.Default,
Type: this.Type,
})
}
}

func (this *SchemaField) String() string {
return fmt.Sprintf("[SchemaField: Name: %s, Doc: %s, Default: %v, Type: %s]", this.Name, this.Doc, this.Default, this.Type)
}
Expand Down

0 comments on commit 61ed6d7

Please sign in to comment.