1

I have an ASP.Net Core 3.1 project which serves APIs.

Some of my apis interact with an Oracle DB, to get some dataset

Here is a short example of what one of my api does:

    [HttpGet]
    [Route("api/GetMySpecificData")]
    public IActionResult getData()
    {
        ...
        var ds = new DataSet();
        OracleDataAdapter adapter = new OracleDataAdapter(query, connection);
        adapter.Fill(ds);
        return Ok(ds.Tables[0]);
    }

In my Oracle DB, column names are UPPER_SNAKE_CASED and I expect my Api to return the Dataset with the same format for the property names. (Example : USER_ID). Instead my client receives a different format for column names : useR_ID.

I don't know at all how to fix this, but what I want is to receive property names with the same format that it is set in the DB Column Name

I use this piece of code in my startup.cs ConfigureServices function :

services.AddControllers().AddNewtonsoftJson()

Maybe I have to add some options to specify this behaviour but I have no idea.

aynber
  • 22,380
  • 8
  • 50
  • 63
Sonny Jayet
  • 434
  • 2
  • 7
  • 24
  • FYI OracleDataAdapter has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260 Source: https://learn.microsoft.com/en-us/dotnet/api/system.data.oracleclient.oracledataadapter – Bernard Vander Beken Mar 03 '22 at 10:15

2 Answers2

1

I think what I need is maybe to make Newtonsoft.Json case sensitive.

What I ended up to do is the following :

        services.AddControllers().AddNewtonsoftJson( options =>
        {
            options.UseMemberCasing();
        });
Sonny Jayet
  • 434
  • 2
  • 7
  • 24
0

Try using below code:

Starup.cs

services.AddControllers().AddJsonOptions(jsonOptions =>
{
    jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null;
})

In Asp.net Core 3 by default PropertyNamingPolicy is camelCase and set it to null will solve your problem.

Satinder singh
  • 10,100
  • 16
  • 60
  • 102
  • I tried this already, and there are no changes when I use this. I tried to put it after / before the AddNewtonsoftJson() line. If I remove the AddNewtonsoftJson() Line I get an error "Serialization and deserialization of 'System.Type' instances are not supported and should be avoided" after request my api – Sonny Jayet Mar 03 '22 at 10:39