no need to call toJSON if not serializing

Minor tweak...

I noticed that the code was calling `attr.toJSON` then ignoring the result if not serializing.  so moved the `toJSON` call into the `if (serialize)` branch.