{"action":"created","issue":{"url":"https://api.github.com/repos/RevenantX/LiteNetLib/issues/215","repository_url":"https://api.github.com/repos/RevenantX/LiteNetLib","labels_url":"https://api.github.com/repos/RevenantX/LiteNetLib/issues/215/labels{/name}","comments_url":"https://api.github.com/repos/RevenantX/LiteNetLib/issues/215/comments","events_url":"https://api.github.com/repos/RevenantX/LiteNetLib/issues/215/events","html_url":"https://github.com/RevenantX/LiteNetLib/issues/215","id":355936980,"node_id":"MDU6SXNzdWUzNTU5MzY5ODA=","number":215,"title":"Question: NetSerializer and backward compatibility","user":{"login":"xmedeko","id":1101801,"node_id":"MDQ6VXNlcjExMDE4MDE=","avatar_url":"https://avatars0.githubusercontent.com/u/1101801?v=4","gravatar_id":"","url":"https://api.github.com/users/xmedeko","html_url":"https://github.com/xmedeko","followers_url":"https://api.github.com/users/xmedeko/followers","following_url":"https://api.github.com/users/xmedeko/following{/other_user}","gists_url":"https://api.github.com/users/xmedeko/gists{/gist_id}","starred_url":"https://api.github.com/users/xmedeko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xmedeko/subscriptions","organizations_url":"https://api.github.com/users/xmedeko/orgs","repos_url":"https://api.github.com/users/xmedeko/repos","events_url":"https://api.github.com/users/xmedeko/events{/privacy}","received_events_url":"https://api.github.com/users/xmedeko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-31T11:04:22Z","updated_at":"2018-08-31T15:25:49Z","closed_at":null,"author_association":"NONE","body":"We want to maintain at least some backward compatibility with server and clients of different version. E.g. we have a class `Person` in the client v1. Then we want add the property `int Color` for the client v2 with default value `Color = 0` for the old v1 client.  Each client sends it's version with the `ConnectRequest` and I keep it as `NetPeer.Tag`.\r\n\r\nHow to solve this case using `NetSerializer`? Is there any way how to deserialize `Person` on the server  for each client?\r\n\r\nThe only solution I have found is to make a new class `Person2` and the server must keep both: `Person` and `Person2`.\r\nThanks\r\n"},"comment":{"url":"https://api.github.com/repos/RevenantX/LiteNetLib/issues/comments/417699472","html_url":"https://github.com/RevenantX/LiteNetLib/issues/215#issuecomment-417699472","issue_url":"https://api.github.com/repos/RevenantX/LiteNetLib/issues/215","id":417699472,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNzY5OTQ3Mg==","user":{"login":"Orsidus","id":7916674,"node_id":"MDQ6VXNlcjc5MTY2NzQ=","avatar_url":"https://avatars0.githubusercontent.com/u/7916674?v=4","gravatar_id":"","url":"https://api.github.com/users/Orsidus","html_url":"https://github.com/Orsidus","followers_url":"https://api.github.com/users/Orsidus/followers","following_url":"https://api.github.com/users/Orsidus/following{/other_user}","gists_url":"https://api.github.com/users/Orsidus/gists{/gist_id}","starred_url":"https://api.github.com/users/Orsidus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Orsidus/subscriptions","organizations_url":"https://api.github.com/users/Orsidus/orgs","repos_url":"https://api.github.com/users/Orsidus/repos","events_url":"https://api.github.com/users/Orsidus/events{/privacy}","received_events_url":"https://api.github.com/users/Orsidus/received_events","type":"User","site_admin":false},"created_at":"2018-08-31T15:25:49Z","updated_at":"2018-08-31T15:25:49Z","author_association":"NONE","body":"Yes it is possible. Use polymorphism. Create a new class that extends Person with your new stuff i.e \r\n\r\n```\r\npublic class PersonV2 : Person\r\n{\r\n\tpublic int color = 2;\r\n\r\n\tpublic int Color\r\n\t{\r\n\t\tget => color;\r\n\t\tset => color = value;\r\n\t}\r\n}\r\n```\r\n\r\nThen register both Person and PersonV2 on the server to either the same processor the different process it doesn't matter. You can then check the type server side with something like \r\n\r\n_serializer.SubscribeReusable<Person>(new Action(Process));\r\n_serializer.SubscribeReusable<PersonV2>(new Action(Process));\r\n\r\n```\r\nprivate static void Process(Person data)\r\n{\r\n\tif (data.GetType() == typeof(PersonV2))\r\n\t{\r\n\t\tConsole.WriteLine(\"Is Person V2\");\r\n\t}\r\n\telse\r\n\t{\r\n\t\tConsole.WriteLine(\"Is Person V1\");\r\n\t}\r\n}\r\n```\r\n\r\nSince PersonV2 derrives from Person it can be passed as a Person internally.\r\n\r\n"}}
{"actor":{"display_login":"Orsidus"}}