refactored to support function getAsString($obj)