Skip to content

Commit

Permalink
Added a custom JsonSerializer settings example. (#135)
Browse files Browse the repository at this point in the history
* Update README.md, added a custom JsonSerializer settings example
  • Loading branch information
PureKrome authored and abatishchev committed Oct 29, 2017
1 parent 66c6344 commit bc1bf97
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,28 @@ IJsonSerializer serializer = new CustomJsonSerializer();
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder);
```

### Custom JSON serialization settings with the default JsonNetSerializer

As mentioned above, the default JSON serialization is done by `JsonNetSerializer`. You can define your own custom serialization settings as follows:

```csharp
JsonSerializer customJsonSerializer = new JsonSerializer
{
// All json keys start with lowercase characters instead of the exact casing of the model/property. e.g. fullName
ContractResolver = new CamelCasePropertyNamesContractResolver(),

// Nice and easy to read, but you can also do Formatting.None to reduce the payload size (by hardly anything...)
Formatting = Formatting.Indented,

// The best date/time format/standard.
DateFormatHandling = DateFormatHandling.IsoDateFormat,

// Don't add key/values when the value is null.
NullValueHandling = NullValueHandling.Ignore,

   // Use the enum string-value, not the implicit int value, e.g. "oolor" : "red"
Converters.Add(new StringEnumConverter())
};
IJsonSerializer serializer = new JsonNetSerializer(customJsonSerializer);
```

0 comments on commit bc1bf97

Please sign in to comment.