Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7308435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:33:25+00:00 2026-05-28T23:33:25+00:00

I am attempting to take an object structured like so public class Item {

  • 0

I am attempting to take an object structured like so

public class Item
{
   public Guid SourceTypeID {get;set;}
   public Guid BrokerID {get;set;}
   public double Latitude {get;set;}
   public double Longitude {get;set;}
   public DateTime TimeStamp {get;set;}
   public object Payload {get;set;}
}

and serialize it with JSON.NET using a call like:

Item expected = new Item()
{
   SourceTypeID = Guid.NewGuid(),
   BrokerID = Guid.NewGuid(),
   Latitude = 33.657145,
   Longitude = -117.766684,
   TimeStamp = DateTime.Now,
   Payload = new byte[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
};
string jsonString = JsonConvert.SerializeObject(expected);

The payload member of the Item object will potentially hold any one primitive of a list of C# primitives (plus a few others like Guid), or an array of those types (as in the example, a byte array), or a “flat” object composed of any of those previously listed “primitives” (dynamically created).

When I perform the SerializeObject() call, the string that is produced contains:

{"Payload":"AAECAwQFBgcICQ==","SourceTypeID":"d8220a4b-75b1-4b7a-8112-b7bdae956a45",
 "BrokerID":"951663c4-924e-4c86-a57a-7ed737501dbd",
 "TimeStamp":"\/Date(1328202421559-0600)\/",
 "Latitude":33.657145,"Longitude":-117.766684}

However when I make the deserializing call the item that is produced is partially incorrect

Item actual = JsonConvert.DeserializeObject<Item>(jsonString);

actual.SourceTypeID : {00000000-0000-0000-0000-000000000000}
actual.BrokerID : {951663c4-924e-4c86-a57a-7ed737501dbd}
actual.Latitude : 33.657145;
actual.Longitude : -117.766684;
actual.TimeStamp : {2/2/2012 11:07:01 AM}
actual.Payload : null

The SourceTypeID member (Guid), and the Payload member (object, holding a byte[]), are both incorrect. The serialized string seems to hold the right identity for the guid, but not for the byte array.

I see that an alternate signatureof SerializeObject is

SerializeObject(object value, params JsonConverter[] converters);

Is this the correct way to inform the de/serialization engine about types that it apparently handles wrong? Since I am working with a limited set of “primitives” at the core of my object, if I could create a set of converters for each of those types, would that solve my problem?

I want to avoid reinventing the wheel if possible, as it seems that this would be a problem that has already been handled gracefully, and I’d like to leverage something like that if available.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T23:33:26+00:00Added an answer on May 28, 2026 at 11:33 pm

    This appears to be an actual bug in JSON.NET.

    It’s not idea, but a workaround might be to have a two-stage serialization. The first, the object that actually gets serialized to/from JSON, would consist only of fields/properties with string type. The second object (the one your server-side code would use) would be an object that is converted to strong types manually.

    Not ideal, but possible. Additonally, you could consider using the DataContractJsonSerializer, which does a pretty good job of handling byte arrays and guids IME. Dates are still pretty sucky, but that’s mostly the fault of Javascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to take the Name and ID fields from each object, but
I am attempting to develop a class with a function that can take a
As someone who is attempting to take a more object oriented approach to my
I am attempting to take a list of objects, and turn that list into
I'm attempting to take Excel 2003 and connect it to SQL Server 2000 to
Basically Im attempting to take a php / jquery / css / html web
I'm attempting to take an NSImage and convert it to a string which I
Im attempting to take a string that is in a partial comma separated setup.
I'm attempting to take 4-5 fields from a large django form and display them
I'm attempting to take values from a XML file and put them into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.