/** * Creates a new parameter with the given {@code name} and {@code value}. * * @param name The parameter name. * @param value The parameter value. * @param jsonMapper Mapper for converting the parameter value to JSON. * @throws IllegalArgumentException If {@code name} is {@code null} or a blank string or either * {@code value} or {@code jsonMapper} is {@code null}. */ private Parameter(String name, Object value, JsonMapper jsonMapper) { if (isBlank(name) || value == null) throw new IllegalArgumentException(Parameter.class + " instances must have a non-blank name and non-null value."); if (jsonMapper == null) throw new IllegalArgumentException("Provided " + JsonMapper.class + " must not be null."); this.name = trimToEmpty(name).toLowerCase(); // Special handling for Date types - turn them into Facebook date strings. // Otherwise, use the JSON value of the type. this.value = value instanceof Date ? new SimpleDateFormat(FACEBOOK_LONG_DATE_FORMAT).format(value) : jsonMapper .toJson(value); }
/** * Creates a new parameter with the given {@code name} and {@code value}. * * @param name * The parameter name. * @param value * The parameter value. * @param jsonMapper * Mapper for converting the parameter value to JSON. * @throws IllegalArgumentException * If {@code name} is {@code null} or a blank string or either {@code value} or {@code jsonMapper} is * {@code null}. */ private Parameter(String name, Object value, JsonMapper jsonMapper) { if (isBlank(name) || value == null) { throw new IllegalArgumentException(Parameter.class + " instances must have a non-blank name and non-null value." + " Got instead name:" + name + ", value:" + value); } if (jsonMapper == null) { throw new IllegalArgumentException("Provided " + JsonMapper.class + " must not be null."); } this.name = trimToEmpty(name); // Use the JSON value of the type. this.value = jsonMapper.toJson(value, true); }
/** * @see com.restfb.FacebookClient#executeBatch(java.util.List, java.util.List) */ @Override public List<BatchResponse> executeBatch(List<BatchRequest> batchRequests, List<BinaryAttachment> binaryAttachments) { verifyParameterPresence("binaryAttachments", binaryAttachments); if (batchRequests == null || batchRequests.isEmpty()) { throw new IllegalArgumentException("You must specify at least one batch request."); } return jsonMapper.toJavaList( makeRequest("", true, false, binaryAttachments, Parameter.with("batch", jsonMapper.toJson(batchRequests, true))), BatchResponse.class); }