0

I'm calling API using postman, I'm sending dynamic properties using JObject as given below

I'm sending class data to API using JSON but which is ignoring the values of duplicate data

     public class Details
        { 
            public List<JObject> Mappings { get; set; } 

             // adding properties to jobject abd mappings     

            [JsonExtensionData]
            public IDictionary<string, JToken> AdditionalProperties { get; set; }

         }

I'm using below JSON in postman

    {      
      "source": {
            "details": "Sample Customer",
            "compoet": "Sample Site",
            "Name": "Sample Software",
            "Version": "1.0.1",
            "Creator": "Sample Company"
        },
      "Mappings":[
      {
        "data": Test.Name1",
        "data": Test.Name23",    
        "newprop":"Account1",
      }
    {
        "data": "Test.Name2",    
        "newprop":"Account2",
      }
    ]
    }

when I pass duplicate key API is taking second value "data": Test.Name23" I want API should take both values from mapping can anyone help?

dbc
  • 104,963
  • 20
  • 228
  • 340

1 Answers1

0

it's better don't do that, and this is my reason

you can pass "data" value as an array

Mehrdad
  • 1,523
  • 9
  • 23
  • Thank you, In my case, User may pass a duplicate object to API i need to throw the error after verification, but API itself not receiving the duplicate properties. is it possible to allow duplicates? – teja Learn Feb 27 '20 at 10:29
  • you can catch that exception with middleware then do what you need with that. it means you can define a middleware and handle that exception in your own way – Mehrdad Feb 27 '20 at 10:33
  • Middleware in the sense, let's say user using the postman to hit my API controller, where can I build the middleware, and when I receive the data in the controller itself which is removing the duplicate data, do we have any JSON settings to validate this kind of issue? – teja Learn Feb 27 '20 at 10:40
  • no there is not any setting, also you can get your json as a string from your client. then validate it in your controller – Mehrdad Feb 27 '20 at 10:42
  • Thank you, can we throw the exception if we pass duplicate values to API before sends, is there any filter or overrides to catch the entire object – teja Learn Feb 27 '20 at 10:47
  • when you get your json as string? yes we can throw – Mehrdad Feb 27 '20 at 10:50
  • Sure let me try, can we pass same object as a string as well as to object to API call at the same time. – teja Learn Feb 27 '20 at 10:58