0

For example: https://store.steampowered.com/api/appdetails/?appids=435150&filters=basic

The name is 435150 and its values are success and data. If I request another game, the name changes. Let's say 578080.

https://store.steampowered.com/api/appdetails/?appids=578080&filters=basic

 public void readJson(String gameID) throws IOException {
        String targetURL = String.format(STEAM_API, gameID);
        URL url = new URL(targetURL);
        InputStreamReader reader = new InputStreamReader(url.openStream());
        ObjectMapper mapper = new ObjectMapper();
        SteamResponseWrapper wrapper = mapper.readValue(reader, SteamResponseWrapper.class);
        System.out.println(wrapper.getSteamResponse().getGame().toString());
    }

public class SteamResponseWrapper {
      private String gameID;
      private SteamResponse steamResponse;
    }

public class SteamResponse {
      private boolean success;
      private Game game;
    }

public class Game {
      private String name;
      private int steam_appid;
    }

I get this error Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "435150" (class util.SteamResponseWrapper), not marked as ignorable (2 known properties: "steamResponse", "gameID"])

  • Can you modify the format of the json? – NiVeR Jun 20 '18 at 19:32
  • You may mark your class to ignore unknown fields on deserialization and continue the processing. Unless you really want/need to process this specific field, then use a `Map`. – Luiggi Mendoza Jun 20 '18 at 20:12

1 Answers1

0

How about reading it to Map first, then getting value and parse using Wrapper with success and data property?

Take a look at this.

Peteef
  • 377
  • 1
  • 2
  • 10