I tried to make a custom typemap in SWIG, but I got segfaults when I did that.
I eventually solved the problem by writing a new function in straight JNI that puts the array elements into a jlongArray, rather than letting SWIG write a wrapper function for it.