public static JsonObject ToJsonObject(BaseException baseException) { JsonObject answer = new JsonObject(); answer.put("errorDomain", baseException.ErrorDomain); // null is ok answer.put("faultCode", baseException.FaultCode); answer.put("faultMessage", baseException.Message); answer.put("underlyingFaultMessage", baseException.UnderlyingFaultMessage); answer.put("originator", baseException.getOriginator()); JsonArray jsonStackTrace; { jsonStackTrace = new JsonArray(); String[] stackTrace = ExceptionHelper.getStackTrace(baseException, true); for (int i = 0, count = stackTrace.Length; i < count; i++) { jsonStackTrace.Add(stackTrace[i]); } stackTrace = ExceptionHelper.getStackTrace(baseException, false); for (int i = 0, count = stackTrace.Length; i < count; i++) { jsonStackTrace.Add(stackTrace[i]); } } answer.put("stackTrace", jsonStackTrace); JsonObject faultContext = new JsonObject(); answer.put("faultContext", faultContext); return answer; }