swagger-api / swagger-api/swagger-codegen
[C#] DateTimeFormat not used in objects serialization and deserialization by Newtonsoft Json.Net
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
DateTimeFormat is not managed in the JsonConvert serialization and deserialization.
ParameterToString will correctly use it (see #1706) but for complex objects this settings would not be used.
Swagger-codegen version
swagger-codegen-cli-2.4.8 and online version (https://editor.swagger.io/)
Suggest a fix/enhancement
Two proposed fix in ApiClient.cs:
-
Constructor by configuration
` public ApiClient(Configuration config)
{
Configuration = config ?? Client.Configuration.Default;// here we probably would use Configuration.DateTimeFormat if it's valorized also in serializerSettings for Newtonsoft JsonConvert if (string.IsNullOrEmpty(Configuration.DateTimeFormat)) { serializerSettings.DateFormatString = Configuration.DateTimeFormat; } RestClient = new RestClient(Configuration.BasePath); }` -
The Serialize part
public String Serialize(object obj) { try { return obj != null ? JsonConvert.SerializeObject(obj, serializerSettings /* here we need to pass the serialization settings*/) : null; } catch (Exception e) { throw new ApiException(500, e.Message); } }
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the generated C# ApiClient.cs, reading the serializerSettings setup, Serialize method, and the existing ParameterToString handling referenced in #1706. Trace both object serialization and deserialization, then verify that Configuration.DateTimeFormat is honored consistently; the issue does not name a test, so identify the relevant test location before changing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100