0

i try to deserialize the following JSON:

"{\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.StockObject, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"1\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_16\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"2\",\r\n \"$type\": \"LLL_server.Models.ArtTypeBall, LLL_server\",\r\n \"G_Color\": \"Weiß\",\r\n \"G_Material\": \"Leder\",\r\n \"G_Radius\": 20,\r\n \"G_Descr\": \"Weißer Fussball!\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"3\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_17\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"4\",\r\n \"$type\": \"LLL_server.Models.ArtTypeBall, LLL_server\",\r\n \"G_Color\": \"Rot\",\r\n \"G_Material\": \"Gummi\",\r\n \"G_Radius\": 15,\r\n \"G_Descr\": \"Roter Gummiball!\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"5\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_18\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"6\",\r\n \"$type\": \"LLL_server.Models.ArtTypeBall, LLL_server\",\r\n \"G_Color\": \"Orange\",\r\n \"G_Material\": \"Plastik\",\r\n \"G_Radius\": 2,\r\n \"G_Descr\": \"Tischtennisball Orange!\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"7\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_19\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"8\",\r\n \"$type\": \"LLL_server.Models.ArtTypeBall, LLL_server\",\r\n \"G_Color\": \"Gelb\",\r\n \"G_Material\": \"Gummi\",\r\n \"G_Radius\": 15,\r\n \"G_Descr\": \"Gelber Gummiball!\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"9\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_20\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"10\",\r\n \"$type\": \"LLL_server.Models.ArtTypeBall, LLL_server\",\r\n \"G_Color\": \"Blau\",\r\n \"G_Material\": \"Gummi\",\r\n \"G_Radius\": 15,\r\n \"G_Descr\": \"Blauer Gummiball!\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"11\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_21\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"12\",\r\n \"$type\": \"LLL_server.Models.ArtTypeLamp, LLL_server\",\r\n \"G_Power\": 20,\r\n \"G_Descr\": \"Energiesparlampe\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"13\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_22\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"14\",\r\n \"$type\": \"LLL_server.Models.ArtTypeLamp, LLL_server\",\r\n \"G_Power\": 100,\r\n \"G_Descr\": \"Helle Lampe\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"15\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_1\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"2\"\r\n },\r\n \"G_Place\": {\r\n \"$id\": \"16\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_1\",\r\n \"G_Stock\": {\r\n \"$id\": \"17\",\r\n \"$type\": \"LLL_server.Models.Stock, LLL_server\",\r\n \"G_PlaceList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Place, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"16\"\r\n },\r\n {\r\n \"$id\": \"18\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_2\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"19\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_3\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"20\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_4\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"21\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_5\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"22\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_6\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"23\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_7\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"24\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_8\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"25\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_9\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"26\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_10\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n }\r\n ]\r\n }\r\n }\r\n },\r\n \"G_Position\": {\r\n \"$id\": \"27\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_1\",\r\n \"G_Order\": {\r\n \"$id\": \"28\",\r\n \"$type\": \"LLL_server.Models.Order, LLL_server\",\r\n \"G_CompletelyPicked\": false,\r\n \"G_PositionList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Position, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"27\"\r\n },\r\n {\r\n \"$id\": \"29\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_2\",\r\n \"G_Order\": {\r\n \"$ref\": \"28\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"30\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_3\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"4\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"18\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"29\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n }\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"15\"\r\n },\r\n {\r\n \"$id\": \"31\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_2\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"2\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"16\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"27\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5850625\"\r\n },\r\n {\r\n \"$ref\": \"31\"\r\n },\r\n {\r\n \"$ref\": \"30\"\r\n },\r\n {\r\n \"$id\": \"32\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_4\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"6\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"19\"\r\n },\r\n \"G_Position\": {\r\n \"$id\": \"33\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_3\",\r\n \"G_Order\": {\r\n \"$id\": \"34\",\r\n \"$type\": \"LLL_server.Models.Order, LLL_server\",\r\n \"G_CompletelyPicked\": false,\r\n \"G_PositionList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Position, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"33\"\r\n },\r\n {\r\n \"$id\": \"35\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_4\",\r\n \"G_Order\": {\r\n \"$ref\": \"34\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"36\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_5\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"12\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"20\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"35\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n },\r\n {\r\n \"$id\": \"37\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_5\",\r\n \"G_Order\": {\r\n \"$ref\": \"34\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"38\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_6\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"8\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"21\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"37\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n }\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"32\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$ref\": \"36\"\r\n },\r\n {\r\n \"$ref\": \"38\"\r\n },\r\n {\r\n \"$id\": \"39\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_7\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"10\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"21\"\r\n },\r\n \"G_Position\": {\r\n \"$id\": \"40\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_6\",\r\n \"G_Order\": {\r\n \"$id\": \"41\",\r\n \"$type\": \"LLL_server.Models.Order, LLL_server\",\r\n \"G_CompletelyPicked\": false,\r\n \"G_PositionList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Position, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"40\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"39\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$id\": \"42\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_8\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"12\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"21\"\r\n },\r\n \"G_Position\": {\r\n \"$id\": \"43\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_7\",\r\n \"G_Order\": {\r\n \"$id\": \"44\",\r\n \"$type\": \"LLL_server.Models.Order, LLL_server\",\r\n \"G_CompletelyPicked\": false,\r\n \"G_PositionList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Position, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"43\"\r\n },\r\n {\r\n \"$id\": \"45\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_8\",\r\n \"G_Order\": {\r\n \"$ref\": \"44\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"46\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_9\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"8\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"22\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"45\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n },\r\n {\r\n \"$id\": \"47\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_9\",\r\n \"G_Order\": {\r\n \"$ref\": \"44\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"48\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_10\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"12\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"23\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"47\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n }\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"42\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$ref\": \"46\"\r\n },\r\n {\r\n \"$ref\": \"48\"\r\n },\r\n {\r\n \"$id\": \"49\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_11\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"6\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"24\"\r\n },\r\n \"G_Position\": {\r\n \"$id\": \"50\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_10\",\r\n \"G_Order\": {\r\n \"$id\": \"51\",\r\n \"$type\": \"LLL_server.Models.Order, LLL_server\",\r\n \"G_CompletelyPicked\": false,\r\n \"G_PositionList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Position, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"50\"\r\n },\r\n {\r\n \"$id\": \"52\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_11\",\r\n \"G_Order\": {\r\n \"$ref\": \"51\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"53\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_12\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"4\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"25\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"52\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n },\r\n {\r\n \"$id\": \"54\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_12\",\r\n \"G_Order\": {\r\n \"$ref\": \"51\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"55\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_13\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"14\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"26\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"54\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$id\": \"56\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_14\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"14\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"26\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"54\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$id\": \"57\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_15\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"14\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"26\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"54\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n }\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"49\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$ref\": \"53\"\r\n },\r\n {\r\n \"$ref\": \"55\"\r\n },\r\n {\r\n \"$ref\": \"56\"\r\n },\r\n {\r\n \"$ref\": \"57\"\r\n }\r\n ]\r\n}"

with JSON.NET. It has been created with JSON.NET. The classes from which I want instances to be created:

public class StockObject
{
    public ArticleType G_ArticleType { get; set; }
    public string G_Code { get; set; }
    public Place G_Place { get; set; }
    public Position G_Position { get; set; }
    public string G_StoredAt { get; set; }
    public string Id { get; set; }
    public DateTime ReturnStoredAt
    {
        get { return DateTime.ParseExact(G_StoredAt, "o", CultureInfo.InvariantCulture); }
        set { G_StoredAt = value.ToString("o"); }
    }
}

public class ArticleType
{
    public string G_Descr { get; set; }
    public string Id { get; set; }
    public string Type { get; set; }
}

public class ArtTypeBall : ArticleType
{
    public string G_Color { get; set; }
    public string G_Material { get; set; }
    public string G_Radius { get; set; }
    public string G_Power { get; set; }
}

public class ArtTypeLamp : ArticleType
{
    public string G_Power { get; set; }
}

public class Place
{
    public string G_Name { get; set; }
    public Stock G_Stock { get; set; }
    public string Id { get; set; }
}

public class Stock
{
    public List<Place> G_PlaceList { get; set; }
}

public class Position
{
    public string G_Code { get; set; }
    public List<StockObject> G_ObjectList { get; set; }
    public Order G_Order { get; set; }
    public string G_Picked { get; set; }
    public string Id { get; set; }
}

public class Order
{
    public string G_CompletelyPicked { get; set; }
    public List<Position> G_PositionList { get; set; }
    public string Id { get; set; }
}

the code on the server side where the JSON is created:

[HttpGet]
    public string GetAllStockObjects()
    {
        var L_ObjectList = G_Repository.ReadAll();
        var L_Settings = new JsonSerializerSettings
        {
            PreserveReferencesHandling = PreserveReferencesHandling.Objects,
            TypeNameHandling = TypeNameHandling.All
        };
        return JsonConvert.SerializeObject(L_ObjectList, Formatting.Indented, L_Settings);
    }

and the deserializing Code:

class ObjectDataCollection : ObservableCollection<ObjectData>
{

    public HttpClient G_Client { get; set; }

    public ObjectDataCollection()
    {
        G_Client = new HttpClient();
        G_Client.BaseAddress = new Uri("http://localhost:50115/");
        G_Client.DefaultRequestHeaders.Accept.Clear();
        G_Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        this.Initialize();
    }

    private async void Initialize()
    {
        List<StockObject> L_ObjectList = await GetObjectsAsync();
        foreach (StockObject L_Object in L_ObjectList)
        {
            string L_Place;
            string L_Position;
            string L_ArticleType;
            if (L_Object.G_Place != null)
            {
                L_Place = L_Object.G_Place.G_Name;
            }
            else
            {
                L_Place = "null";
            }
            if (L_Object.G_Position != null)
            {
                L_Position = L_Object.G_Position.G_Code;
            }
            else
            {
                L_Position = "null";
            }
            if (L_Object.G_ArticleType != null)
            {
                L_ArticleType = L_Object.G_ArticleType.G_Descr;
            }
            else
            {
                L_ArticleType = "null";
            }
            this.Add(new ObjectData()
            {
                G_Code = L_Object.G_Code,
                G_Place = L_Place,
                G_Position = L_Position,
                G_ArticleType = L_ArticleType,
            });
        }
    }

    private async Task<List<StockObject>> GetObjectsAsync()
    {
        List<StockObject> L_ObjectList = null;
        HttpResponseMessage L_Response = await G_Client.GetAsync("api/stockobject/getallstockobjects");
        if (L_Response.IsSuccessStatusCode)
        { 
            string L_ResponseAsString = await L_Response.Content.ReadAsStringAsync();
            L_ObjectList = Deserialize<List<StockObject>>(L_ResponseAsString);
        }
        return L_ObjectList;
    }

    private T Deserialize<T>(string I_JSON)
    {
        var L_Settings = new JsonSerializerSettings
        {
            PreserveReferencesHandling = PreserveReferencesHandling.Objects,
            TypeNameHandling = TypeNameHandling.All
        };
        return JsonConvert.DeserializeObject<T>(I_JSON, L_Settings);
    }
}


class ObjectData
{
    public string G_Place { get; set; }
    public string G_Position { get; set; }
    public string G_Code { get; set; }
    public string G_ArticleType { get; set; }
}

The error Message:

Could not cast or convert from System.String to System.Collections.Generic.List`1[TestClientArno.Models.StockObject].

I tried also with:

L_ObjectList = Deserialize<IEnumerable<StockObject>>(L_ResponseAsString);

but this also didn`t work. I'm sure my classes on client-side are wrong, but i can't see where.

Greetings, Robert

  • Can you paste a version without escaping the json – TheGeneral Jun 10 '18 at 20:42
  • No luck with json too? https://stackoverflow.com/questions/50777952/error-while-deserializing-xml-in-c-sharp . My guess, it is a problem with your server code and you double-serialize your return object – Eser Jun 10 '18 at 20:43
  • @TheGeneral sry I don't understand (I'm german and my english is not the best). What do you mean with "without escaping the json"? This is the exact string I get from the server. – Robert Arnold Jun 10 '18 at 20:49
  • Please reduce this to a [mcve]. After "unescaping", this is 672 lines of JSON and a couple of hundred lines of code. A minimal example demonstrating the same problem is likely to be about 5 lines of JSON and about 20 lines of code... and in reducing the problem to that minimal example, you're likely to find out what's wrong. – Jon Skeet Jun 10 '18 at 20:50
  • @Eser well I use a ASP.NET web API 2 and the controller method returns a string. Is it possible it gets serialized a second time from the web API framework from .Net? – Robert Arnold Jun 10 '18 at 20:53
  • @RobertArnold `This is the exact string I get from the server` seems like i am correct at my guess. Your server method returns a *string* and you use a Json parser to serialize your object and return that string. Make your method return the real object.. – Eser Jun 10 '18 at 20:53
  • Yeah this is fairly strange json to say the least. What ever you are trying to do its seemingly the hard way – TheGeneral Jun 10 '18 at 20:59
  • But I need the Object to be serialized with Json.Net and not with the serializer from web API, because I want to preserve references. When 2 StockObjects references to the same ArticleType they should reference to the same instance after derserialization. I hope you understand my issue. – Robert Arnold Jun 10 '18 at 21:07
  • @RobertArnold I understand your issue but this is not the correct way to write an *API/Service*. Suppose for ex, in the future, your collegue will want to use your service in java/php/js etc. What would those "$type" and "$ref' mean to it. – Eser Jun 10 '18 at 21:11
  • @Eser There's nothing wrong with the `$type` elements. They can be ignored by any decent JSON parser if required. Here they are giving useful metadata. – DavidG Jun 10 '18 at 21:13
  • @DavidG Did you get what I want try to say or just try to explain what "$type" means? (I use Json.Net for many years. I know what it means) – Eser Jun 10 '18 at 21:15
  • @Eser No, I'm saying they are needed for this JSON, specifically due to the inheritance used in the models. – DavidG Jun 10 '18 at 21:20
  • @DavidG And this is exactly what should be avoided when writing a service. How a client consumes the json should be left to the client. Multiple references to the same object or using totally different classes and hierarchies.... Server code shouldn't make any assumption of the client – Eser Jun 10 '18 at 21:22
  • If you want to strip out the `"$type"` information from the incoming JSON and use your own types instead, see [deserialize string that was serialized with TypeNameHandling.All](https://stackoverflow.com/q/47802385/3744182) and/or [Is it possible to set Json.Net to ignore $type?](https://stackoverflow.com/q/48159442/3744182). Basically it's easy to ignore `"$type"` when applied to **objects** but requires some work to ignore them when dealing with **arrays**. Those two questions deal with that scenario. – dbc Jun 10 '18 at 22:01

1 Answers1

1

While I understand Eser's point (a API should be as lightweighted as possible), I will post my solution for everybody who want's a API like this (whith preserving references und inheritence):

suprisingly I found out, that you can use Json.Net serializer with web API 2 simply by using it's default json-serializer. The webapiconfig.cs should look like this:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Web-API-Routen
        config.MapHttpAttributeRoutes();
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        // Web-API-Konfiguration und -Dienste
        var L_SerBinder = new SerBinder();
        config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
        config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Objects;
        config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
        config.Formatters.JsonFormatter.SerializerSettings.SerializationBinder = L_SerBinder;
    }
}

and here is the SerBinder-class, which is needed to avoid namespace-problems:

public class SerBinder : ISerializationBinder
{
    public IList<Type> G_KnownTypes;

    public SerBinder()
    {
        G_KnownTypes = new List<Type>();
        G_KnownTypes.Add(typeof(ArticleType));
        G_KnownTypes.Add(typeof(ArtTypeBall));
        G_KnownTypes.Add(typeof(ArtTypeLamp));
        G_KnownTypes.Add(typeof(Stock));
        G_KnownTypes.Add(typeof(StockObject));
        G_KnownTypes.Add(typeof(Order));
        G_KnownTypes.Add(typeof(Position));
        G_KnownTypes.Add(typeof(Place));
    }

    public Type BindToType(string assemblyName, string typeName)
    {
        return G_KnownTypes.SingleOrDefault(t => t.Name == typeName);
    }

    public void BindToName(Type serializedType, out string assemblyName, out string typeName)
    {
        assemblyName = null;
        typeName = serializedType.Name;
    }
}

you need also

using Newtonsoft.Json.Serialization;

for the "ISerializationBinder"-Interface. G_KnownTypes has to be filled with all classnames you want to deserialize.

On the Clientside:

private T Deserialize<T>(string I_JSON)
    {
        var L_SerBinder = new SerBinder();
        var L_Settings = new JsonSerializerSettings
        {
            PreserveReferencesHandling = PreserveReferencesHandling.Objects,
            TypeNameHandling = TypeNameHandling.Objects,
            SerializationBinder = L_SerBinder,
        };
        return JsonConvert.DeserializeObject<T>(I_JSON, L_Settings);
    }

of course you have to implement the same SerBinder-class on clientside.