Serialization of a large list in JSON.Net

3

I have a problem with the serialization of an object (a list of a class with approximately 5000 items).

I am using JSON.NET to generate the Json string but it is getting the following problem, in the middle of it is a text like this:

,{"State":0,"DataAlteracao":null,"Id":0,"IdDadosRastreamento":0,"CodigoPeriferico":"0","ValorPeriferico":"0"}
,{"State":0,"DataAlteracao":null,"Id":0,"IdDadosRastreamento":0,"CodigoPeriferico":"0","ValorPeriferico":"0"}
,{"State":0,"DataAl:..."0","ValorPeriferico":"1840"}
,{"State":0,"DataAlteracao":null,"Id":0,"IdDadosRastreamento":0,"CodigoPeriferico":"0","ValorPeriferico":"1380"}
,{"State":0,"DataAlteracao":null,"Id":0,"IdDadosRastreamento":0,"CodigoPeriferico":"0","ValorPeriferico":"62"}

Notice in bold that he cut off the tag name as well as put "..." and then proceeded to create the file normally.

Does anyone know what this problem can be and how can I resolve it? the code to perform the serialization is as follows:

string jsonReq = Newtonsoft.Json.JsonConvert.SerializeObject(request);

Where request is the list with 5000 positions.

    
asked by anonymous 23.12.2015 / 14:35

2 answers

1

As commented, I believe that if you are returning a very large list, you should ideally add the following properties to your server:

  • Receiving variables for paging: page number requested, number of records per page (the client can specify this, but on the server you check if both the page number starts with 1 and is no more than the number of existing records and also that the number of records per page is not greater than, say, 100 records, or something that allows the response not to be very large);

  • Stipulate a default sort even if the client does not have authority to ask for this information. In general, it depends on context. But assuming it's an incremental list, it may be legal to sort by descending date. If the customer asks for the first page with 100 records, it takes the first 100 most recent. Then if it turns out that he did not have any of this information he uses them, and then moves on to the next page. Until you get a record he has locally. Hence he need not ask for the previous pages. In general this approach makes more sense than starting from the earliest to the most recent date. If the return list is never sorted, your customer will never be able to do this.

  • It's generally nice to add this information to the% response% of your request. So your client can check, for example, that he asked for the first 100 records but the server returned that Headers of the response says that there are 1 million records. If the idea is always to page through to the end, you'll have an idea of how much remains to be done. Using X-Record-Count also facilitates not having to encapsulate the result in another object with this information.

  • 23.12.2015 / 18:29
    -1

    Personally I was able to figure out the size of the POST that was being done, I set up web.config according to the Microsoft documentation:

    I placed the following additional items in web.config:

    <system.web>
    <httpRuntime maxRequestLength="2147483647" targetFramework="4.5" />
    </system.web>
    

    and

      <system.web.extensions>
        <scripting>
          <webServices>
            <jsonSerialization maxJsonLength="50000000"/>
          </webServices>
        </scripting>
      </system.web.extensions>
    
        
    23.12.2015 / 18:30