fix bug in toJSONObject() and serialize()