mardi 11 juillet 2017

Laravel 5.4 - JSON response substract one from number

I encountered weird problem when using Laravel 5.4 and working with unsigned BIGINT field type.

One field in my DB I has values like this:

10156480263320077
10157375840500077
285320181803715
798994416871156
10152807376710077
620382424666122
10152824605589176
824259214287650
10156820510510077

When I try to convert those values to JSON response by using:

return response()->json(['ids' => $ids]);

Some of them had 1 subtracted from them. It is happening only with those ending in 77:

10156480263320077
10157375840500077
10152807376710077
10157375840500077

I fixed my issue by changing them to string instead of numeric before encoding reponse. I think it happens because JSON tries to treat those values as INT instead of BIGINT.

But I am not satisfied with changing values before encoding them. Any idea how I can make it by setting JSON response option? I know that using setEncodingOptions(JSON_NUMERIC_CHECK) will convert strings to numeric values but is there option to do it in other direction and encode numbers as string so this problem will not occur?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ud7cAw
via IFTTT

Aucun commentaire:

Enregistrer un commentaire