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

  • Home
  • SEARCH
  • 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 4581018
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:51:52+00:00 2026-05-21T20:51:52+00:00

I have a complex heirarchy of JSON objects posting to a WCF service. By

  • 0

I have a complex heirarchy of JSON objects posting to a WCF service. By design and other requirements, each JSON object has an integer id representing conceptually its type or field layout (let’s call this the type id).

What I would like to accomplish is control over which .NET type is chosen for each JSON object’s deserialization, through the inspection of each incoming integer type id.

Example input:

{
 "typeId": 4,
 "someField1": "foo",
 "someField2": "bar",
 "otherObject": 
    {
     "typeId": 7
     "someField3": "abc",
     "someField4": "xyz"
    }
}

Example (Ideal) Process:

1. I receive partially parsed object.
2. I inspect "typeId" which has value 4.
3. I notify the deserialization process that I elect to use my .NET type FooBarA.
4. I receive partially parsed object.
5. I inspect "typeId" which has value 7.
6. I notify the deserialization process that I elect to use my .NET type FooBarB.

Is this or similar possible to do? I seem to recall asmx-style services used to include a __type field similar to my type id I suppose, but I don’t recall its exact purpose or whether that can be enabled in WCF as an alternative perhaps.

  • 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-21T20:51:53+00:00Added an answer on May 21, 2026 at 8:51 pm

    You can collect the incoming JSON as a either a string (if you want the “concrete” type) or you can accept the JSON as a Stream (very useful if you are in a REST based scenario) and then copy it into a MemoryStream for processing several times over. Since the DataContractJsonSerializer works off the Stream, your best use case is dumping it into the MemoryStream.

    The deserialization use case you are describing is going to be rather difficult to pull off because if the nested object (in your case “otherObject”) is not a member of the parent class (in this case FooBarA) then the deserialization process is just going to ignore the value because it has nowhere to put it.

    Switching gears, a more time consuming process would use Json.Net and you could step through the JSON in a similar style as you would with Linq to XML. The advantage of Json.Net is that it allows you to play with JSON that doesn’t necessarily map perfectly to concrete classes. It doesn’t play nicely with WCF in the serialization chain, but I’ve used it a few times on the WCF side to deal with JSON that gets supplied that doesn’t match up exactly with what an concrete class is looking for.

    You can find Json.Net here – http://json.codeplex.com/

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

Sidebar

Related Questions

I have two complex (i.e. objects with string, int, double, List and other home
I have a complex WPF UserControl made of other ContentControl templates which contain sets
If i have a complex object, what is the best practice pattern to write
I have a complex hierarchy of nested objects, with all of the child objects
from the design point of view, I have a complex GUI, what is the
I have a fairly complex content management system I've written in PHP, which has
I have a complex query with group by and order by clause and I
I have a complex .NET Remoting server app that provides a couple of services.
I have a complex command that I'd like to make a shell/bash script of.
I have some complex stored procedures that may return many thousands of rows, and

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.