Sowmya Sirsi

Sowmya Sirsi

  • NA
  • 173
  • 44.6k

The object depth is larger than the maximum allowed depth of 32.

Jul 2 2021 12:13 PM

Hi Team,

Creating a web API using .net core 5

I was getting a error as" A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32."

After adding few library in startup.cs as below:

services.AddControllers().AddJsonOptions(o => o.JsonSerializerOptions
                .ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.Preserve);

Getting Response as below:

{

    "$id": "1",

    "$values": [

        {

            "$id": "2",

            "id": 1,

            "customerName": "ABC",

            "customerMsisdn": "255678765678",

            "bankName": "AXIS",

            "wakalaCode": "1234",

            "accountNumber": "123456544",

            "channelId": 1,

            "referenceId": "gagsfccfc"

        }

    ]

}

My concern is I want the response as below:

   {       

             "id": 1,

            "customerName": "Suchismita",

            "customerMsisdn": "255678765678",

            "bankName": "AXIS",

            "wakalaCode": "1234",

            "accountNumber": "123456544",

            "channelId": 1,

            "referenceId": "gagsfccfc"

}

Not getting why these extra fields are getting added

 "$id": "1",

    "$values": [

        {

            "$id": "2",

Can anyone  assist please?

Thanks

 

 


Answers (2)