public JsonValue Serialize(object obj, JsonMapper mapper)
        {
            Invitation invitation = (Invitation)obj;

            JsonObject result = new JsonObject();

            result.AddValue("subject", new JsonValue(invitation.Subject));
            result.AddValue("body", new JsonValue(invitation.Body));

            JsonObject recipients = new JsonObject();
            JsonArray  people     = new JsonArray();
            JsonObject person     = new JsonObject();

            if (invitation.Recipient.ID != null)
            {
                person.AddValue("_path", new JsonValue("/people/" + invitation.Recipient.ID));
            }
            else
            {
                person.AddValue("_path", new JsonValue("/people/email=" + invitation.Recipient.Email));
                person.AddValue("first-name", new JsonValue(invitation.Recipient.FirstName));
                person.AddValue("last-name", new JsonValue(invitation.Recipient.LastName));
            }
            JsonObject personValue = new JsonObject();

            personValue.AddValue("person", person);
            people.AddValue(personValue);
            recipients.AddValue("values", people);
            result.AddValue("recipients", recipients);

            JsonObject itemContent = new JsonObject();
            JsonObject request     = new JsonObject();

            request.AddValue("connect-type", new JsonValue("friend"));
            if (invitation.Recipient.AuthToken != null)
            {
                string[]   authToken     = invitation.Recipient.AuthToken.Split(':');
                JsonObject authorization = new JsonObject();
                authorization.AddValue("name", new JsonValue(authToken[0]));
                authorization.AddValue("value", new JsonValue(authToken[1]));
                request.AddValue("authorization", authorization);
            }
            itemContent.AddValue("invitation-request", request);
            result.AddValue("item-content", itemContent);

            return(result);
        }
        public JsonValue Serialize(object obj, JsonMapper mapper)
        {
            Message message = (Message)obj;

            JsonObject result = new JsonObject();
            result.AddValue("subject", new JsonValue(message.Subject));
            result.AddValue("body", new JsonValue(message.Body));

            JsonObject recipients = new JsonObject();
            JsonArray people = new JsonArray();
            foreach (string id in message.RecipientIds)
            {
                JsonObject person = new JsonObject();
                person.AddValue("_path", new JsonValue("/people/" + id));

                JsonObject personValue = new JsonObject();
                personValue.AddValue("person", person);
                people.AddValue(personValue);
            }
            recipients.AddValue("values", people);
            result.AddValue("recipients", recipients);

            return result;
        }