use indented json in ONM.String()

to be consistent with the logged request/CGREvent. only used by logs
This commit is contained in:
ionutboangiu
2026-02-19 18:02:12 +02:00
committed by Dan Christian Bogos
parent 4bde2fc07c
commit af6e29362e
3 changed files with 31 additions and 2 deletions

View File

@@ -2017,6 +2017,27 @@ func TestGetEndOfMonth(t *testing.T) {
}
}
// go test ./utils/ -bench BenchmarkToJSON -benchtime=1s -benchmem
func BenchmarkToJSON(b *testing.B) {
v := map[string]any{
"Result-Code": "2001",
"Granted-Service-Unit": map[string]any{
"CC-Time": 300,
},
"Session-Id": "cgrates;1052943642;938",
}
b.Run("ToJSON", func(b *testing.B) {
for b.Loop() {
ToJSON(v)
}
})
b.Run("ToIJSON", func(b *testing.B) {
for b.Loop() {
ToIJSON(v)
}
})
}
func TestParseBinarySize(t *testing.T) {
type args struct {
size string

View File

@@ -42,7 +42,7 @@ type OrderedNavigableMap struct {
// String returns the map as json string
func (onm *OrderedNavigableMap) String() string {
return ToJSON(onm.nm)
return ToIJSON(onm.nm)
}
// GetFirstElement returns the first element from the order

View File

@@ -892,7 +892,15 @@ func TestOrderedNavigableMapString(t *testing.T) {
},
},
}
onmExpect := `{"Map":{"test1":{"Value":{"Data":"data!"}}}}`
onmExpect := `{
"Map": {
"test1": {
"Value": {
"Data": "data!"
}
}
}
}`
if onm.String() != onmExpect {
t.Errorf("Expected %s but received %s", onmExpect, onm.String())
}