ontehfritz / api.mtgdb.info

Project closing first of August 2015
http://www.mtgdb.info/
MIT License
36 stars 8 forks source link

Different field names when using "fields" query? #85

Closed alotau closed 10 years ago

alotau commented 10 years ago

When using the query:

http://api.mtgdb.info/cards/?fields=id,name,cardsetid

The returned JSON for the first card is: {"Id":1,"Name":"Ankh of Mishra","CardSetId":"LEA"}

However on a more "regular" query like: http://api.mtgdb.info/cards/1

The returned JSON for that same card is: {"id":1,"relatedCardId":0,"setNumber":6,"name":"Ankh of Mishra","searchName":"ankhofmishra","description":"Whenever a land enters the battlefield, Ankh of Mishra deals 2 damage to that land's controller.","flavor":"","colors":["None"],"manaCost":"2","convertedManaCost":2,"cardSetName":"Limited Edition Alpha","type":"Artifact","subType":null,"power":0,"toughness":0,"loyalty":0,"rarity":"Rare","artist":"Amy Weber","cardSetId":"LEA","token":false,"promo":false,"rulings":[{"releasedAt":"2004-10-04","rule":"This triggers on any land entering the battlefield. This includes playing a land or putting a land onto the battlefield using a spell or ability."},{"releasedAt":"2004-10-04","rule":"It determines the land's controller at the time the ability resolves. If the land leaves the battlefield before the ability resolves, the land's last controller before it left is used."}],"formats":[{"name":"Legacy","legality":"Legal"},{"name":"Vintage","legality":"Legal"},{"name":"Freeform","legality":"Legal"},{"name":"Prismatic","legality":"Legal"},{"name":"Tribal Wars Legacy","legality":"Legal"},{"name":"Classic","legality":"Legal"},{"name":"Singleton 100","legality":"Legal"},{"name":"Commander","legality":"Legal"}],"releasedAt":"1993-08-05"}

The key difference here is that the field names are different. Note "Id" versus "id" and "Name" versus "name".

This change ruins the "fields" API call for the Java library. If there is an easy fix, the Java users would really appreciate it. Specifically, if the field names in the "fields" type of query were the same as the other queries, that would be ideal.

alotau commented 10 years ago

So I created a workaround in the Java API for this issue, but I think it still might be something you'd want to address in the future. Not a burning priority for me.

ontehfritz commented 10 years ago

I will fix this tomorrow my time zone. Thanks for pointing it out! It should all be the same and javascript case.

ontehfritz commented 10 years ago

@alotau hey this should be done. Let me know if this is ok with you! Then I will close this issue.

All json serialization should be all camel case now. The issue was using LINQ and selecting just the fields from the card object into a anonymous type, once it was anonymous type it no longer honoured the JSON attributes that I had set on the card object. I bootstrapped all JSON serialization across the board it should always use camelCase!

alotau commented 10 years ago

The fix I implemented in the java client takes the field name and does a toLowerCase on it. So as long as you don't have two different fields with names like 'fieldOne' and 'fieldone' I should be OK. I'll probably leave my fix in place until I have some other need to touch the code again (and I may leave it even after that).

ontehfritz commented 10 years ago

Sounds good. I will close this. Field names should be the same no matter what method pulled.