﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33974	Serializer incorrectly serializes Integer ArrayField as string	Arthur Hanson	nobody	"If you define a model with an ArrayField of type Integer (PositiveSmallInteger, etc..) and use the built in serializer to json it will be serialized as an array of strings.  Expected is that it will be serialized as an array of integers.  For example, given the model below:

{{{
from django.db import models

# Create your models here.
from django.contrib.postgres.fields import ArrayField
from django.db import models

class Board(models.Model):
    pieces = ArrayField(
        base_field=models.PositiveSmallIntegerField()
    )

}}}

If you create an object with ""pieces = [1, 3, 5, ]"" and either create a fixture or call serialize directly you will get an array of strings.  The following management command shows the issue:

{{{
from django.core.management.base import BaseCommand, CommandError
from serializertest.models import Board
from django.core.serializers import serialize
import json

class Command(BaseCommand):
    help = ''

    def handle(self, *args, **options):
        obj = Board.objects.first()
        if not obj:
            pieces = [1, 3, 5]
            obj = Board()
            obj.pieces = pieces
            obj.save()

        print(serialize('json', [obj]))
        print(json.dumps(obj.pieces))
}}}

Output will be:

[{""model"": ""serializertest.board"", ""pk"": 1, ""fields"": {""pieces"": ""[\""1\"", \""3\"", \""5\""]""}}]
[1, 3, 5]

Note: the serialize output an array of strings, while calling json directly will give the expected array of integers. "	New feature	closed	Core (Serialization)	4.0	Normal	wontfix			Unreviewed	0	0	0	0	0	0
