StevenL.3761:

For /v1, I used to have a single class per item type to hold type-specific item details.

Statically typed languages like C# do not allow “item.details” objects to take on different types according to the value of “item.type”.

For /v2, I need to rethink my design so that every possible item detail fits into a single class hierarchy.

Is anyone trying to do the same thing? Did you run into any problems with things like duplicate property names meaning different things for different item types?

edit

Does anyone use JSON schema validation? Is there a way to generate an aggregate schema from a number of different json documents? It would be interesting to see a tool that loops through all 38k items, then outputs a complete schema that describes all possible objects and properties.

poke.3712:

Statically typed languages like C# do not allow “item.details” objects to take on different types according to the value of “item.type”.

While that is true, you could still have some abstract `ItemDetails` type that has various different implementations depending on the item type. Or even better, have a base `Item` type and make a subtype for each item type that extends the type by those additional properties in the `details` object. That way, you would also get a proper type in C# (and wouldn’t need to check the item’s `type` value).

Depending on how you are parsing the JSON, you might be able to put this into a custom parser that creates the proper subtype depending on the `type` value.

Does anyone use JSON schema validation?

JSON schema validation was invented by XML people who thought they would need to add whatever XML had as JSON replaced XML in web services. But JSON was meant as a dynamic format, so having a schema doesn’t really make sense to me…

It would be interesting to see a tool that loops through all 38k items, then outputs a complete schema that describes all possible objects and properties.

I looked at all items, and ended up with the documentation. Hope it helps

StevenL.3761:

I would prefer schemas over custom converters. I think that you could write a schema that only matches objects with a specific value for the “type” property. So you’d write one schema for each possible type, then use those schemas to determine which class to use for serialization.

Your documentation was very helpful though. In the end, I ended up with this class layout: https://gw2dotnet.codeplex.com/SourceControl/latest#GW2.NET/Code/GW2.NET.Core/V2/Items.Json/DetailsDataContract.cs

Pat Cavit.9234:

I looked at all items, and ended up with the documentation. Hope it helps

This is so great. Thanks poke!

AysonCurrax.3254:

For /v1, I used to have a single class per item type to hold type-specific item details.

Statically typed languages like C# do not allow “item.details” objects to take on different types according to the value of “item.type”.

For /v2, I need to rethink my design so that every possible item detail fits into a single class hierarchy.

Is anyone trying to do the same thing? Did you run into any problems with things like duplicate property names meaning different things for different item types?

edit

Does anyone use JSON schema validation? Is there a way to generate an aggregate schema from a number of different json documents? It would be interesting to see a tool that loops through all 38k items, then outputs a complete schema that describes all possible objects and properties.

I am currently in the same boat, although i am using Java on my end. My first thought was to have a default “Details” class and then derive other classes from that class for example “DetailsArmor” and “DetailsWeapon” with the respective attributes in them.

I am doubtful that that will work though. previously, I had One class “ItemJSON” with several static subclasses in that class so i could directly Map item_details onto that class and then use the getters and setters to map that onto my more specific objects that go along with my database structure.

So in that case, i would have “ItemJSON.Armor” contain all the info from the “Armor” subobject from the item_details json.

I could have details contain all possible attributes, thus making everything not used NULL, but that would be too lazy and dirty for my taste. Like that one time where i mapped Item_details onto a single database table which ended up having 100 or so columns with several hundred thousand entries. -cough-