Questions tagged [jsonconverter]

111 questions
23
votes
2 answers

Set a value comparer in ASP.NET Core 3.1

I have used "HasConversion" in my DBContext to define a JSonArray (Language/Value) and save it as a Text field for ages and It works like a charm, I added a new project to my solution, nothing changed but then I got a new error on adding migration…
12
votes
1 answer

Asp.Net Core 3.1 Appsettings not respecting JsonConverter

In asp.net core 3.1, using the new System.Text.Json, I am trying to use a custom JsonConverter on an appsettings section. Manually serializing/deserializing respects the converter just fine, but reading from appSettings via Options pattern does…
8
votes
3 answers

Selecting a NamingStrategy when using a JsonConverter on a class property

I've got a c# class that I am trying to correctly serialise using Newtonsoft.Json. The property is an enumeration type and I wish the value to be serialised as the "lowercase version of the enumeration name". There is a JsonConverterAttribute…
Chris Walsh
  • 3,423
  • 2
  • 42
  • 62
8
votes
1 answer

Getting Converters specified via Attributes to be equivalent to global ones in json.net

When using Newtonsoft.Json, I can make it do what I need by adding a converter to the top level SerializerSettings or supplying it to the conversion invocation - all is working well. I'm hoping to extract some of my global converters to instead be…
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
7
votes
1 answer

Serialising BigInteger using System.Text.Json

I'm serialising a BigInteger to JSON using System.Text.Json: JsonSerializer.Serialize(new {foo = new BigInteger(ulong.MaxValue) + 1}) This results in the following…
Neo
  • 4,145
  • 6
  • 53
  • 76
7
votes
1 answer

Token PropertyName in state Property would result in an invalid JSON object. when using custom JsonConverter

I am trying to serialise/deserialise a .NET DataSet using Json.NET and a custom serialiser. I know many of you will tell me not to (I have seen this on other posts) I have a valid reason and wish to continue down this route. My serialisation is…
Martin Robins
  • 6,033
  • 10
  • 58
  • 95
4
votes
2 answers

Writing a custom converter for appsettings.json

I want to create an appsettings.json converter which converts Symbols to IReadOnlyCollection. The converter should split the string by /, which will result into a BaseAsset/QuoteAsset. It should then check whether QuoteAsset equals to…
nop
  • 4,711
  • 6
  • 32
  • 93
4
votes
1 answer

Custom JSON Deserialization in C# with JsonConverter

I have two classes in .Net Core The class Ownership namespace CustomStoreDatabase.Models { public class Ownership { public string OwnershipId { get; set; } public List TextOutput { get; set; } public DateTime…
user5113188
4
votes
2 answers

How to set FloatParseHandling.Decimal for custom JsonConverter?

How can i set FloatParseHandling.Decimal for a custom JsonConverter? we have a struct DecimalDbValue that internally only holds one decimal field that i want to be de/serialized for all its types. It uses a magic number (decimal.MinValue) for…
toebens
  • 4,039
  • 6
  • 24
  • 31
3
votes
2 answers

Serialize a list of Objects of different Classes (implementing a common Interface) rendering only the Interface Properties (as IActionResult)

I wrote a Controller Action that needs to return a Json with a List of Sports. This Json Array only needs to contain the common properties (defined at the Interface level). The Interface definition is: public Interface ISport { string TeamName…
3
votes
0 answers

Custom JsonConverter never gets called by the MVC model binder/controller

I have a custom type that I want the MVC model binder serialize/deserialize using my custom JsonConverter for System.Text.Json. Here is my implementation: public class Enumeration { private readonly string _value; public Enumeration(string…
3
votes
1 answer

Global error handler including Model Binder errors

I work on a AspNet Core 3.1 web-api project which is being tested by PenTest agency and they flag situations when incorrect input data causes response that contains information about project code internals like below: { "type":…
The Yur
  • 432
  • 5
  • 13
3
votes
1 answer

StringEnumConverter works as an attribute but not globally

We are implementing a .NET Core 3.1 API and we are using Microsoft.AspNetCore.Mvc.NewtonsoftJson according to this doc. We are dealing with enums and we need the string representation instead of the integers. We are doing it using the JsonConverter…
user33276346
  • 1,501
  • 1
  • 19
  • 38
3
votes
2 answers

Deserialize json to object in c# does not map values

I'm trying to deserialize a json string by using the Jsonconverter. I have all the values inside the json, I also want to mention that, that specific json is being generated from the swagger, so when i send a payload to the API it maps it into the…
Csibi Norbert
  • 780
  • 1
  • 11
  • 35
3
votes
1 answer

How to Serialize using JSON.NET and Ignore a Nullable Struct Value

I am trying to serialize a nullable struct using JSON.NET with a custom JsonConverter. I would like a null value to be ignored/omitted in the JSON output e.g. I want my JSON output below to be {} instead of {"Number":null}. How can this be achieved?…
Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
1
2 3 4 5 6 7 8