Questions tagged [datacontractjsonserializer]

DataContractJsonSerializer is a .NET component that makes it possible to directly serialize .NET objects into JSON data and to deserialize such data back into instances of .NET types.

DataContractJsonSerializer is part of the Microsoft (version 3.5 onwards). It makes it possible to directly serialize .NET objects into data and to deserialize such data back into instances of .NET types.

As with (with which it shares an abstract base class XmlObjectSerializer), DataContractJsonSerializer is intended to serialize data contract types, thus appropriate data contract attributes may be applied to control the serialization of objects from and to JSON.

188 questions
1
vote
2 answers

Detecting the difference between null property and omitted property in JSON

I have a RESTful webservice which receives JSON and it deserialises it into a c# class using the DataContractJsonSerializer, though this can be changed. Its purpose is to update fields on a resource e.g.: { "firstName" : "Martin" } I don't…
Martin Booth
  • 8,485
  • 31
  • 31
0
votes
0 answers

Convert or deserialize string Json to dynamic Type object like typeof(ElementType) or Obj.GetType()

Type elementType = Type.GetType("TestApp.SchoolModel"); string itemJson = "{"SchoolName":"Test School", "OnDate":"\/Date(1685730600000+0530)\/", "OnTime":"23:34:49"}"; Object obj =…
0
votes
0 answers

Deserialize protobuf json using DataContractSerializer

I will give a shot asking here as seemingly simple question but hard to find answer.. maybe for some people this is a common sense.. When one microservice uses Protobuf to build classes and serialize in json, can another microservice deserialize…
swcraft
  • 2,014
  • 3
  • 22
  • 43
0
votes
0 answers

ExtensionDataObject - Members are private. How do I read/write?

The goal is to read/write json files that contain custom properties. The typical advice is to use the ExtensionDataObject class. However, I can't find any information online as to how I actually read/write the data to this object. I have run a test…
0
votes
1 answer

DataContractJsonSerializer contains invalid UFT8 bytes

When I try to deserialize a JSON file with a 'Ñ' I get the exception: 'Exception has been thrown by the target of an invocation. ---> System.Xml.XmlException: '� 1' contains invalid UTF8 bytes. ---> System.Text.DecoderFallbackException: Unable to…
0
votes
0 answers

DataContractJsonSerializer with NetworkStream

i want to use the DataContractJsonSerializer class in combination with the TcpClient to receive and send JSON serialized objects. I am able to send JSON serialized objects but the receiving part does not work. Source code of sending…
0
votes
0 answers

Setting an additional caller-defined context for DataContractJsonSerializer

For BinaryFormatter I can set an additional caller-defined context, which will be passed as parameter to the method called after deserialization, e.g. decorated with [OnDeserialized] attribute. Calling the method decorated with [OnDeserialized] for…
0
votes
0 answers

Does IExtensibleDataObject work with EmitDefaultValue option and DataContractJsonSerializer?

I want to design an API that accept some generic contract and also can store additional values that extends generic schema. It looks like IExtensibleDataObject machinery was built for similar task and it can be useful for my usecase. But, when I try…
0
votes
0 answers

Parse JSON string to dynamic object without creating class using System.Runtime.Serialization.Json

The JSON string that I want to parse is the response from the API and the response may not have fixed properties. So cannot create a class with properties to parse the JSON string. I tried to parse the JSON string to dynamic/Expando object but it…
0
votes
0 answers

How does DataContractJsonSerializer.ReadObject(XmlReader, Boolean) read json from an XmlReader?

I'm looking at the ms documentation for DataContractJsonSerializer which lists an overload for ReadObject: ReadObject(XmlReader, Boolean) The documentation states: Reads an XML document mapped from JSON with an XmlReader and returns the…
Jeremy
  • 44,950
  • 68
  • 206
  • 332
0
votes
1 answer

System.Text.Json.Deserialize an array into C# class

First off, I am working with the Google recaptcha RESTful service trying to get the JSON object into a class. With WSDL's, Visual Studio will generate all this code for you so that it is easy to work with, but RESTful it seems you have to do…
0
votes
0 answers

C# DataContract force PascalCase output

The DataContract likes to accept the input properties in PascalCase (as the property names are in PascalCase as well in C#) unless I manually set the property name to camelCase (using JsonProperty). But doesn't the same doesn't let me output in…
Arvind Sasikumar
  • 482
  • 3
  • 15
0
votes
1 answer

Getting InvalidDataContractException while serializing with DataContractJsonSerializer

I have the following Json stored as Dynamics Environment Variable: { "LogLevel": 3, "ServiceEndpointId": "11111111-2222-3333-4444-555555555555", "ServiceEndpointType": 1 } What I get when I retrieve the configuration is the following: Seen in the…
0
votes
1 answer

VB.NET DataContractJsonSerializer Nested Object Formatting

I have a problem with the outcome of a serialization. The class i serialize looks like this: Public Class ResponseJSON Public Property…
0
votes
1 answer

Silverlight json won't serialize

I have been trying to serialize some json data in Silverlight. I am using the following code System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new…
kereberos
  • 1,253
  • 1
  • 10
  • 20