System.Text.Json.JsonException: The input does not contain any JSON tokens
Another reason this error could pop up, as it did for me, is simply because the API endpoint doesn’t exist because it was misspelled.
Another reason this error could pop up, as it did for me, is simply because the API endpoint doesn’t exist because it was misspelled.
your date value in your JSON isn’t correct. should be 2019-01-06T17:16:40 Most parsers use ISO 8601
Use this this site for representation: https://quicktype.io/csharp/ something like this may help you public class Item322A { public string prop1 { get; set; } public string prop2 { get; set; } public int prop3 { get; set; } public bool prop4 { get; set; } } public class Item2B { public string prop1 { get; … Read more
Update (2023-10-07): Check the comments in the question for other answers and this answer in the same question for pydantic 2.0 or newer. Switch aliases and field names and use the allow_population_by_field_name model config option: class TMDB_Category(BaseModel): strCategory: str = Field(alias=”name”) strCategoryDescription: str = Field(alias=”description”) class Config: allow_population_by_field_name = True Let the aliases configure the … Read more
You are on the right track. You do need to implement a custom JsonConverter for your Holder class to handle this situation, as you suggested. But, don’t worry, it is possible to write the converter in such a way that you can use the original reader and serializer instances passed to the converter, without ever … Read more
You can achieve your desired result. You need to switch to NewtonsoftJson serialization (from package Microsoft.AspNetCore.Mvc.NewtonsoftJson) Call this in Startup.cs in the ConfigureServices method: services.AddControllers().AddNewtonsoftJson(); After this, your constructor will be called by deserialization. Extra info: I am using ASP Net Core 3.1 Later Edit: I wanted to give more info on this, as it … Read more
A simpler way I found (just now) to do this is to use the @SerializedName annotation. I found it in the EnumTest.java here (the Gender class around ln 195): https://code.google.com/p/google-gson/source/browse/trunk/gson/src/test/java/com/google/gson/functional/EnumTest.java?r=1230 This assumes that all of your Types will come in as lowercase as opposed to being “case insensitive” public enum Type { @SerializedName(“live”) LIVE, @SerializedName(“upcoming”) … Read more
As you’ve correctly diagnosed in your update, the issue is that the JSON has a closing ] followed immediately by an opening [ to start the next set. This format makes the JSON invalid when taken as a whole, and that is why Json.NET throws an error. Fortunately, this problem seems to come up often … Read more
As of Jackson 2.12.2, the following accomplishes the goal using the “deduction-based polymorphism” feature. If properties distinct to the Bird subtype (i.e. wingspan) are present, the deserialized type will be Bird; else it will be Animal: @JsonTypeInfo(use=Id.DEDUCTION, defaultImpl = Animal.class) @JsonSubTypes({@Type(Bird.class)}) public class Animal { public String name; public int age; } Deduction-based polymorphism The … Read more
You don’t necessary need a custom JsonConverter you can use the built in StringEnumConverter with the combination of the EnumMemberAttribute (from the System.Runtime.Serialization assembly). Without the EnumMemberAttribute it uses the enum names so Artist, Contemporary, etc so you need to change the names with it to your A,C, etc value. But it is not the … Read more