-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The collection type 'Newtonsoft.Json.Linq.JObject' on 'Stripe.Checkout.Session.RawJObject' is not supported. #1979
Comments
@sstalder Thanks for the report! EDIT: Sorry it looks like your issue is different and we're looking into it. |
Sorry I should of also gave an example. This happens when simply trying to serialize a Session object from a controller.
|
Thanks for the report @sstalder, and sorry for the trouble. My take on the issue is that it's expected that var e = // some StripeEntity object
var json = e.ToJson();
var deserialized = StripeEntity.FromJson(json); That said, System.Text.Json is not just any "random" JSON library -- it looks like it's in a good place to become the new standard JSON library for modern .NET apps. We aren't quite ready to make the switch from Newtonsoft.Json to System.Text.Json in Stripe.net itself, though we may do so in the future. In the meantime, I think you'd have to write a custom converter to be able to serialize namespace YourApp
{
public class StripeEntityConverter : JsonConverter<StripeEntity>
{
public override StripeEntity Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options) =>
StripeEntity.FromJson(reader.GetString());
public override void Write(
Utf8JsonWriter writer,
StripeEntity stripeEntity,
JsonSerializerOptions options) =>
writer.WriteString(stripeEntity.ToJson());
}
} Would that work for you? |
I wasn't aware of the json methods you had, thank you for that. I think the converter is a good alternative in the mean time. I completely understand not 100% supporting a somewhat new json library. Thanks for the quick assistance! |
Glad I could help. I'm going to keep this issue open for the time being, and we'll spend some time investigating other possible solutions -- at the very least, we can document this somewhere so users of System.Text.Json know what to expect. If you could report here to confirm whether the custom converter solution works for you or not, I'd really appreciate it too. |
It looks like the custom converter does work, if anyone needs to go that route in the meantime. |
I've just run into this as well. Any update here? |
Stripe API's return is a JSON object with sake_case properties.
|
@ob-stripe Thanks a lot for mentioning this! We just encountered the same problem in serialization and will try that custom json converter |
Wouldn't it be a better idea to return the following from the controller action?
This way it would keep working even if/when Stripe.net migrates to System.Text.Json |
Hi, I think I am having a similar issue. Is there any updates on this? I have a net core 5 site using Microsoft.AspNetCore.Mvc.NewtonsoftJson Trying to read the json posted via webhook which used to work on core 3.1 var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync(); I get: This exception was originally thrown at this call stack: |
@joffnerd , The json you are trying to parse probably not doesn't have "object": "event", as a property. That was my proble and using the right Json fixed my issue. The id should begin with "evt_". |
Looks like this topic has been kicking around for two years now, with no clear guidance on using Stripe, System.Text.Json along with Newtonsoft.Json in a webapp. I'm just beginning to integrate stripe in an existing dotnetcore v6 website and have thus far avoided using Newtonsoft.Json. What I assumed would be a simple integration has begun to look a bit, er, daunting. Q1. Snake case naming
Won't this globally mess up my existing controllers which don't use snake case naming? Or is there an alternative way to link Newtonsoft.Json to just the payment controller? This link implies that it's not possible: Q2. This post explains how to use Newtonsoft.Json and System.Text.Json side-by-side but the implementation doesn't look trivial: Do I really need to jump through this hoop? Much Later... |
Stripe v35.11.0
#1970
This breaks my dotnet core 3 project not using Newtonsoft.Json as the serializer, and I would assume anyone using System.Text.Json.
This is due to the JsonIgnore attribute from Newtonsoft not being used by System.Text.Json as it has it's own attribute.
There is some more information under this section on the migration guide: https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to#conditionally-ignore-a-property
The text was updated successfully, but these errors were encountered: