Viincenttt / MollieApi

This project allows you to easily add the Mollie payment provider to your application.
MIT License
148 stars 85 forks source link

[JsonSerializerSettings] Unprocessable Entity Non-existent body parameter "$id" #280

Closed david-bauduin closed 1 year ago

david-bauduin commented 1 year ago

Hello,

At first thanks for this library,

When i tried to implement the library in my existing net core 3.1 project, the response of mollie was always : "{\"status\":422,\"title\":\"Unprocessable Entity\",\"detail\":\"Non-existent body parameter \\\"$id\\\" for this API call. Did you mean: \\\"name\\\"?\",\"field\":\"$id\",\"_links\":{\"documentation\":{\"href\":\"https://docs.mollie.com/overview/handling-errors\",\"type\":\"text/html\"}}}"

after implementing your project as a ref, it seems than your JsonConverterService doesn't implement a PreserveReferencesHandling = PreserveReferencesHandling.None, so if the base project not implement a JsonSerializeSettings with this parameter, the id is added by default to the serialize : image

adding the PreserveReferencesHandling to the JsonConverterService did the job : image

Have a good day !

Viincenttt commented 1 year ago

Hi @stddd ,

Thanks for the feedback, I haven't encountered this issue before. Could you tell me a little bit more on how to replicate this issue? I would have thought that if this was an issue, it should also occur when I run the integration tests of the project.

If it wouldn't be too much trouble, could you add a sample on how to replicate this issue and attach it?

Kind regards, Vincent

david-bauduin commented 1 year ago

After reviewing why this is happen only in my API, I forgot my own implementation of JsonSerializerSettings for the need of the project so in my startup.cs ConfigureServices : JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore, TypeNameHandling = TypeNameHandling.None, ContractResolver = new CamelCasePropertyNamesContractResolver(), ReferenceLoopHandling = ReferenceLoopHandling.Ignore, PreserveReferencesHandling = PreserveReferencesHandling.Objects };

when we try to call : image

The problem occurs.

Viincenttt commented 1 year ago

Hi @stddd ,

Thanks for the code sample. I've added a commit to fix this.

Kind regards, Vincent