return jsonArray;
}
if (object instanceof Map<?, ?>) {
JsonObject jsonObject = new JsonObject();
for (Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
if (!(entry.getKey() instanceof String))
throw new FacebookJsonMappingException("Your Map keys must be of type " + String.class
+ " in order to be converted to JSON. Offending map is " + object);
try {
jsonObject.put((String) entry.getKey(), toJsonInternal(entry.getValue(), ignoreNullValuedProperties));
} catch (JsonException e) {
throw new FacebookJsonMappingException("Unable to process value '" + entry.getValue() + "' for key '"
+ entry.getKey() + "' in Map " + object, e);
}
}
return jsonObject;
}
if (isPrimitive(object))
return object;
if (object instanceof BigInteger)
return ((BigInteger) object).longValue();
if (object instanceof BigDecimal)
return ((BigDecimal) object).doubleValue();
// We've passed the special-case bits, so let's try to marshal this as a
// plain old Javabean...
List<FieldWithAnnotation<Facebook>> fieldsWithAnnotation =
findFieldsWithAnnotation(object.getClass(), Facebook.class);
JsonObject jsonObject = new JsonObject();
// No longer throw an exception in this case. If there are multiple fields
// with the same @Facebook value, it's luck of the draw which is picked for
// JSON marshaling.
// TODO: A better implementation would query each duplicate-mapped field. If
// it has is a non-null value and the other duplicate values are null, use
// the non-null field.
Set<String> facebookFieldNamesWithMultipleMappings = facebookFieldNamesWithMultipleMappings(fieldsWithAnnotation);
if (facebookFieldNamesWithMultipleMappings.size() > 0 && logger.isLoggable(FINE))
logger.fine(format("Unable to convert to JSON because multiple @" + Facebook.class.getSimpleName()
+ " annotations for the same name are present: " + facebookFieldNamesWithMultipleMappings));
for (FieldWithAnnotation<Facebook> fieldWithAnnotation : fieldsWithAnnotation) {
String facebookFieldName = getFacebookFieldName(fieldWithAnnotation);
fieldWithAnnotation.getField().setAccessible(true);
try {
Object fieldValue = fieldWithAnnotation.getField().get(object);
if (!(ignoreNullValuedProperties && fieldValue == null))
jsonObject.put(facebookFieldName, toJsonInternal(fieldValue, ignoreNullValuedProperties));
} catch (Exception e) {
throw new FacebookJsonMappingException("Unable to process field '" + facebookFieldName + "' for "
+ object.getClass(), e);
}
}