2

I am making a call to the Steam Storefront api and am trying to model the data in java but am having trouble wrapping my head around how to do so because of a slight issue.

So, say you make a call Appid 57690 = Tropico 4

http://store.steampowered.com/api/appdetails?appids=57690

It will return with the header {"57690": {... rest of json }}

But if you make the call to Appid 570 = Dota 2

http://store.steampowered.com/api/appdetails?appids=570

It will return with the header {"570": {... rest of json }}

How do you create the POJO's to model this, because it is a header?

3
  • The root is just a String.. Commented Jun 23, 2017 at 19:57
  • Question: What are you exactly using to read/write objects from/into JSON data? Commented Jun 23, 2017 at 19:58
  • I plan on using retrofit @DragShot Commented Jun 23, 2017 at 19:59

1 Answer 1

1

Just create a class, inside add one property of type "String" and then an object for the rest of the JSON.

For example

public class MyClass{
  public String rootId = "";
  public SteamObj steamObj = new SteamObj();
}

public class SteamObj {
  //Who knows what
}

Either way you can make use of this tool to generate the POJO for you:

http://www.jsonschema2pojo.org/

Sign up to request clarification or add additional context in comments.

1 Comment

Oh okay for some reason I had in my head that there needed to be a static, unchanging name like "Response" or "Message" at the header of a Json file, thanks for clearing that up

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.