This is a result of my previous question Lightning component action responds with internal server error which I was finaly able to troubleshoot and resolve on my own.
My original issue was that my apex controller method expected an integer but the JSON was deserializing as a string. This is actually not a problem as I'm using the number in a string anyway so it actually cleans up the code a bit.
Or so I thought...
After fixing that Issue I began getting "illegal argument" errors in the apex logs. The line of code that it was pointing to was:
resultSize = String.escapeSingleQuotes(resultSize);
Which I added since it was a string param and I was using it in a dynamic query. The question is, if JSON deserialized it as a String into a String param, why would this cause an illegal argument error when trying to use it as a String?
I was able to resolve the error by the following:
resultSize = String.escapeSingleQuotes(String.valueOf(resultSize));
but the question remains, why does it seem SF is having such a hard time serializing an integer correctly and what is the best pattern to use to reduce these errors?