Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Serializing objects to JSON with properties that return interfaces

Reply
Thread Tools

Serializing objects to JSON with properties that return interfaces

 
 
Ra Carter
Guest
Posts: n/a
 
      03-14-2010
I want to serialize and deserialize an object to and from JSON. My
code looks something like this:

http://pastebin.com/yB5idwNq

This gives me an error like this:

System.Runtime.Serialization.SerializationExceptio n: Type 'MyObject1'
with data contract name 'MyObject1:http://schemas.datacontract.org/
2004/07/namespace' is not expected. Add any types not known statically
to the list of known types - for example, by using the
KnownTypeAttribute attribute or by adding them to the list of known
types passed to DataContractSerializer.

I am only using ISerializable because [Serializable] [DataContract]
would not work of course. The main problem I think I am having is that
I have declared my return type as an interface.

I don't want to change my objects and it is actually important that I
return the interface and not the implementation for various reasons.
What can be done? if Serializable or DataContract attributes won't
work automatically, can I pull this off manually using Serializable?
 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      03-17-2010
http://social.msdn.microsoft.com/For...f-c0859e041e85
http://blogs.msdn.com/sowmy/archive/...nowntypes.aspx

Please post your solution after you figure out, so others can learn from it.





"Ra Carter" <> wrote in message
news:172f43fb-c4e1-47b6-b433-...
>I want to serialize and deserialize an object to and from JSON. My
> code looks something like this:
>
> http://pastebin.com/yB5idwNq
>
> This gives me an error like this:
>
> System.Runtime.Serialization.SerializationExceptio n: Type 'MyObject1'
> with data contract name 'MyObject1:http://schemas.datacontract.org/
> 2004/07/namespace' is not expected. Add any types not known statically
> to the list of known types - for example, by using the
> KnownTypeAttribute attribute or by adding them to the list of known
> types passed to DataContractSerializer.
>
> I am only using ISerializable because [Serializable] [DataContract]
> would not work of course. The main problem I think I am having is that
> I have declared my return type as an interface.
>
> I don't want to change my objects and it is actually important that I
> return the interface and not the implementation for various reasons.
> What can be done? if Serializable or DataContract attributes won't
> work automatically, can I pull this off manually using Serializable?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Lib to generate XML/JSON[P] output from a DTD/XSD/JSON Schema/etc Acácio Centeno Python 1 02-15-2013 07:34 AM
I am facing an issue while decoding json string using json.loads sajuptpm Python 2 12-28-2012 07:16 AM
[ANN] Security Fix json-1.1.7 for json_pure and json gems Florian Frank Ruby 0 06-30-2009 05:18 PM
"JSON for ASP" at json.org Tuðrul Topuz ASP General 1 06-27-2008 11:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57