Skip to content

Commit

Permalink
Fixed arrays processing ( arrays can be part of arrays or object )
Browse files Browse the repository at this point in the history
Fixed processing of sub-objects
(cherry picked from commit aec1260)
  • Loading branch information
vladpaiu committed Oct 3, 2014
1 parent f4f6028 commit 914f140
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions modules/cachedb_mongodb/cachedb_mongodb_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,24 @@ void bson_to_json_generic(struct json_object *obj,bson_iterator *it,int type)
obj2 = json_object_new_array();
bson_iterator_subiterator(it, &it2 );
bson_to_json_generic(obj2,&it2,BSON_ARRAY);
json_object_object_add(obj,curr_key,obj2);
//json_object_put(obj2);
if (type == BSON_OBJECT)
json_object_object_add(obj,curr_key,obj2);
else if (type == BSON_ARRAY)
json_object_array_add(obj,obj2);
break;
case BSON_OBJECT:
LM_DBG("Found key %s with type object\n",curr_key);
obj2 = json_object_new_object();
bson_iterator_subiterator(it, &it2 );
bson_to_json_generic(obj2,&it2,BSON_OBJECT);
if (type == BSON_OBJECT)
json_object_object_add(obj,curr_key,obj2);
else if (type == BSON_ARRAY)
json_object_array_add(obj,obj2);
break;
default:
/* TODO - support embedded documents */
LM_DBG("Unsupported type %d for key %s - skipping\n",
bson_iterator_type(it),curr_key);
break;
}
}
}
Expand Down

0 comments on commit 914f140

Please sign in to comment.