I currently use Json.Net throughout my project and it works like a charm. Unfortunately, the input binding for Azure Functions use System.Text.Json to deserialize the EventGrid event json and bind it toEventGridEvent object from the Azure.Messaging.EventGrid 4.0.0.-beta.4 library
have a look here: https://github.com/Azure/azure-functions-host/issues/5469
This causes massive problems as all my custom JsonConverters that i have do not work at all which leads to incorrectly deserialized objects. Changing from Newtonsoft.Json to System.Text.Json is a massive amount of rework and i would absolutely like to avoid that, if i can.
Is there a way to force the input bindings to use Json.Net instead of System.Text.Jsoneither via DI in FunctionssStartup.Configure() or otherwise?
Related
I automatically generate schema for my classes using Json.NET Schema and it works great for validation. I wanted to add the ability for my classes to provide snippets directly and emit them into a (presumably separate) schema file, for use in Visual Studio Code.
https://code.visualstudio.com/docs/languages/json#_define-snippets-in-json-schemas
This is a non-standard schema extension of course. From the source code of Json.NET Schema, it looks like I cannot override the class that is used to serialize the schema to JSON, so I can't figure out how to make this work.
The only approach I have considered is to emit the schema, read it back as dumb JSON and then edit in the snippets. The resulting file could be a .vsschema or something like that and presumably no longer valid in the schema validator, so I would store it next to the "clean" one. Is there any nice way to do this that doesn't require me to path through the resulting JSON and make edits that way?
I have a class which contains other classes as properties.
I wrote a little test app and my class serialized with Json.NET just fine.
However, when I try to serialize the same class in a much bigger project, I only get the class names of the nested objects in my json string, not the serialized content.
My question: is there any known problem trying to use Json.NET in conjunction with other libraries? My class has protobuf attributes which do not seem to make a difference in my test app.
I am using .NET 4.5.1
How do I set system properties for raw Java classes used from C# code through IKVM?
I am dealing with some Java code that has been ported to C# using IKVM. Some of the classes have been wrapped in C# classes, but not all of the Java API yet. So I have two versions of some classes, and because only a small part of the API has been wrapped, I have to use the raw Java classes directly in my C# code.
When I use the C# wrapped version, I can parse UTF-8 encoded XML files correctly. When I try to use the underlying Java class directly, I get parsing errors ("content not allowed in prolog") which indicate the wrong charset is being used to parse.
In Java we solve encoding issues by setting -Dfile.encoding=UTF-8, and I am trying to do the same in C# as follows:
static FeedSample()
{
java.lang.System.setProperty("file.encoding", "UTF-8");
}
This setting is picked up when I use the C# wrapper class. When I use the underlying Java class directly, the system property is not picked up. I think I am missing something obvious here. I also tried putting -Dfile.encoding as a command line argument but that did not help.
Here's my problem.
I'm using SOAP to retrieve information from a third-party web service.
Response time is too high, so I was planning on using JSON instead, at least in a couple of methods.
For this I'm using DataContractJsonSerializer, but I seem to be having some trouble.
For example, in SOAP there's a method called getAvailablePublic with returns an object of type getAvailablePublicResponse.
There's an equivalent for this method in JSON, which also returns a an object of type getAvailablePublicResponse.
In order to deserialize the information I needed to create a couple of data contracts, and here are my concerns:
Do I really need to create a DataContract? Why can't I use getAvailablePublicResponse object from asmx?
The problem is that if I create a DataContract, I need to use a different name other than getAvailablePublicResponse, as I would have two objects with the same name (the one created by me, and the one from SOAP), and this would require making several changes in my solution.
Hope this makes sense.
Thanks.
Can you post your client code that is making the call to the web service? I don't know what you are using now, but I'm a fan of RestSharp for making remote calls and serializing JSON to C# classes. Something like this:
RestClient client = new RestClient("http://some.domain.com/someservice?someparam=yes");
var results = client.Execute<MyGreatDTOClass>(new RestRequest(Method.GET));
Looking for a way to do something like the following:
NewtonSoft.Json.JsonConvert.Populate<IMyContract>(jsonStr, currentObj);
where the json.net engine would only attempt to populate the properties that are identified in the IMyContract.
Any suggestions?
Maybe u can use
PopulateObject(String, Object, JsonSerializerSettings)
And use your own JsonSerializerSettings. See: http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_JsonSerializerSettings.htm
Try to use one of the delegates to restrict the properties that are set yourself. That can be based on an Interface, using reflection.
I don't know any other way. If you don't get it with the JsonSerializerSettings you can always write your own PopulateObject method using the Json framework.