Giter Site home page Giter Site logo

Comments (2)

patrickmichalina avatar patrickmichalina commented on June 12, 2024

I have been struggling to figure out why the webhooks are failing when consuming them via a normal Web API POST endpoint. I found that I need to remove an additional "" in a "\n" otherwise the parsing fails due to an "illegal character" error.

from braintree_dotnet.

EvanHahn avatar EvanHahn commented on June 12, 2024

JSON (de)serialization isn’t something we’re planning on adding. We don’t want to get in the business of adding serialization functionality. Since the part of the Braintree API that this SDK speaks with is XML-based, we’re not going to introduce other encodings for the time being.

You can use Json.NET’s JsonConverter functionality to serialize WebHookNotificiations yourself. Here’s a simple example:

private class WebHookNotificationConverter : JsonConverter
{
  public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
  {
    JToken t = JToken.FromObject(value);
    JObject o = (JObject)t;

    WebhookNotification note = (WebhookNotification)value;

    JObject webhookKind = new JObject();
    webhookKind.AddFirst(new JProperty("Name", note.Kind.ToString()));
    o.Remove("Kind");
    o.Add(new JProperty("Kind", webhookKind));

    o.WriteTo(writer);
  }

  public override bool CanRead
  {
    get { return false; }
  }

  public override bool CanConvert(Type objectType)
  {
    return true;
  }
}

string json = JsonConvert.SerializeObject(notification, Formatting.Indented, new WebHookNotificationConverter());

Deserialization is a bit trickier. Since we don’t (and have no plans to) expose public setters for these model objects, it would be tough sledding to write a deserializer for WebhookNotification, or any object in this SDK. However, since this SDK supports XML out of the box, you can always use the built in XML encoding and decoding functionality.

I realize this isn’t a great answer and doesn’t help your immediate use case, but I hope this gets you at least part of the way there. Thanks for opening an issue!

from braintree_dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.