/* (non-Javadoc)
   * @see com.funambol.json.converter.Converter#toJSON(java.lang.Object)
   */
  public String toJSON(JsonAuthResponse jsonAuthResponse) {
    JSONObject jsonRoot = new JSONObject();
    JSONObject jsonData = new JSONObject();

    jsonData.element(JsonAuthResponseModel.SESSIONID.getValue(), jsonAuthResponse.getSessionID());
    jsonRoot.element(JsonAuthResponseModel.DATA.getValue(), jsonData);

    return jsonRoot.toString();
  }
  /* (non-Javadoc)
   * @see com.funambol.json.converter.Converter#fromJSON(java.lang.String)
   */
  public JsonAuthResponse fromJSON(String jsonContent) {
    JSONObject jsonRoot = JSONObject.fromObject(jsonContent);
    JSONObject jsonData = jsonRoot.getJSONObject(JsonAuthResponseModel.DATA.getValue());
    Logger.info("JsonAuthResponse fromJSON's data: " + jsonData.toString());

    JsonAuthResponse jsonAuthResponse = new JsonAuthResponse();
    Logger.info(
        "JsonAuthResponse fromJSON's sessionid: "
            + jsonData.getString(JsonAuthResponseModel.SESSIONID.getValue()));
    jsonAuthResponse.setSessionID(jsonData.getString(JsonAuthResponseModel.SESSIONID.getValue()));

    // this property will be used when the customer needs to
    // use the unique ID instead of the username that comes from the client;
    // this happens when the username from the client is a sort of alias
    String customerUserID = jsonData.optString(customerUserIdLabel);
    if (customerUserID != null) {
      jsonAuthResponse.setCustomerUserID(customerUserID);
    }

    return jsonAuthResponse;
  }