return jsonObject;
}
case RECORD: {
final ObjectNode jsonObject = JSON_NODE_FACTORY.objectNode();
final IndexedRecord record = (IndexedRecord) value;
if (!record.getSchema().equals(schema)) {
throw new IOException(String.format(
"Avro schema specifies record type '%s' but got '%s'.",
schema.getFullName(), record.getSchema().getFullName()));
}
for (Schema.Field field : schema.getFields()) {
final Object fieldValue = record.get(field.pos());
final JsonNode fieldNode = toJsonNode(fieldValue, field.schema());
// Outputs the field only if its value differs from the field's default:
if ((field.defaultValue() == null) || !fieldNode.equals(field.defaultValue())) {
jsonObject.put(field.name(), fieldNode);
}