isString, not isJsonPrimitive: gson's asString stringifies a number or boolean and cannot be told not to, so {"code": 123} would compile and run 123. Absent (or JSON null) reads as missing; a null return means present with the wrong type, which the caller refuses rather than folding into missing.