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 9209179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:46:51+00:00 2026-06-18T00:46:51+00:00

I’m using the Servicestack.Text package to serialize and deserialize objects to and from JSON.

  • 0

I’m using the Servicestack.Text package to serialize and deserialize objects to and from JSON. One of my objects has a property of type object (System.Object). It is one of three things: a long, a double, a string. However, when I use JsonSerializer.DeserializeFromString it is always deserialized as a string. I need it deserialized as the type it was when it was serialized. I tried including the type information with JsConfig.IncludeTypeInfo = true; however, that only appears to apply to the class level, not the property level. How do I make this work?

  • 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-06-18T00:46:53+00:00Added an answer on June 18, 2026 at 12:46 am

    This is not supported in ServiceStack JSON Serializer which looks at the target type that it’s deserializing into for info on how to coerce the JSON value.

    Because you’re using an object property there is no type info so it then fallsback and looks for existence of a __type property for this info, but ServiceStack never emits __type information for ValueTypes as it considerably bloats the payload.

    With no type info to go on, the serializer just leaves the value as a string which is an object.

    I recommend avoiding the use of interfaces, late-bound object types, etc which are a bad idea to have on DTOs, but for this you could create an extension method that inspects the string value and returns an instance of the correct type based on the contents, e.g:

    var dto = new WildCard { AnyObject = 1 };
    
    dto.AnyObject.AsJsonValue(); //Extension method that
    
    "1" -> int 1
    "true" -> bool true
    "anything else" -> string "anything else"
    

    The only issue with this is not being able to send a string literal containing a number or boolean value as it always gets coerced into their respective types.

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

Sidebar

Related Questions

I am using jsonparser to parse data and images obtained from json response. When
I am using JSon response to parse title,date content and thumbnail images and place
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.