Skip to main content

Microsoft Silverlight

Answered Question JSON Serialization and == questionRSS Feed

(0)

Grofit
Grofit

Member

Member

229 points

310 Posts

JSON Serialization and == question

 Hey,

Ive got some objects that are passed around through WCF services and back, one of them is a token that contains a hash and an id. Now the service persists these objects in memory for active users. Then when a user subscribes they are handed one of these tokens to basically verify that they are a valid user when starting other services...

The problem i have is that the flow seems correct but when unserializing the objects dont appear to be the same...

- Contact Service

- Service Generates and Stores Unique Token

- Service Serializes Token to Client

- Client Unserializes Token

- Client Stores Token

- Client Serializes token

- Client Calls Other Service With Serialized Token

- New Service Unserializes Token

- New Service Compares New Token Against All Active Tokens In Memory

 Its at this point it does the TokenListNo == UnserializedToken, and although i can see them both containing the same data  they dont match, im assuming its down to the fact that they are both 2 different objects in memory so it does a comparison on that rather than on the data contained... if thats the case would it be worth implementing the interface that overrides the Equals() method? Or is there something else that is wrong?

waldred
waldred

Member

Member

702 points

113 Posts

Answered Question

Re: JSON Serialization and == question

Grofit:
although i can see them both containing the same data  they dont match, im assuming its down to the fact that they are both 2 different objects in memory so it does a comparison on that rather than on the data contained

My guess is that you're right about that.  Smile

I think you'll want to override Equals() or perform the equality check against whatever properties are appropriate in the 'New Service'.

Grofit
Grofit

Member

Member

229 points

310 Posts

Re: JSON Serialization and == question

 Thought so, thanks for confirming!

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities