Browse Source

Fix `omitempty` in `json.marshal`

Feoramund 1 year ago
parent
commit
309a770cbf
2 changed files with 2 additions and 2 deletions
  1. 1 1
      core/encoding/json/marshal.odin
  2. 1 1
      core/encoding/json/unmarshal.odin

+ 1 - 1
core/encoding/json/marshal.odin

@@ -420,7 +420,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
 				data := rawptr(uintptr(v.data) + info.offsets[i])
 				data := rawptr(uintptr(v.data) + info.offsets[i])
 				the_value := any{data, id}
 				the_value := any{data, id}
 
 
-				if is_omitempty(the_value) {
+				if omitempty && is_omitempty(the_value) {
 					continue
 					continue
 				}
 				}
 
 

+ 1 - 1
core/encoding/json/unmarshal.odin

@@ -348,7 +348,7 @@ json_name_from_tag_value :: proc(value: string) -> (json_name, extra: string) {
 	json_name = value
 	json_name = value
 	if comma_index := strings.index_byte(json_name, ','); comma_index >= 0 {
 	if comma_index := strings.index_byte(json_name, ','); comma_index >= 0 {
 		json_name = json_name[:comma_index]
 		json_name = json_name[:comma_index]
-		extra = json_name[comma_index:]
+		extra = value[1 + comma_index:]
 	}
 	}
 	return
 	return
 }
 }