code: @Override
    public ByteBuffer toBytes(T object) {
      if (!type.equals(object.getClass())) {
        throw new RuntimeException(
            "The type of the object does not match the parameter type of this marshaller. ");
      }
      Map<String, Object> jsonObject = dataMarshaller.mapFieldNameToValue(object);
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      try {
        objectMapper.writeValue(out, jsonObject);
        out.write(NEWLINE_CHARACTER.getBytes());
      } catch (IOException e) {
        throw new RuntimeException("Error in serializing to bigquery json " + jsonObject, e);
      }
      return ByteBuffer.wrap(out.toByteArray());
    }
docs: Validates that the type of the object to serialize is the same as the type for which schema was
  generated. The type should match exactly as interface and abstract classes are not supported.