Example usage for com.fasterxml.jackson.databind ObjectMapper ObjectMapper

List of usage examples for com.fasterxml.jackson.databind ObjectMapper ObjectMapper

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper ObjectMapper.

Prototype

public ObjectMapper() 

Source Link

Document

Default constructor, which will construct the default JsonFactory as necessary, use SerializerProvider as its SerializerProvider , and BeanSerializerFactory as its SerializerFactory .

Usage

From source file:com.krj.karbon.GetOwnedGames.java

public static List<Game> retrieve(String steamId) {
    String urlString = "";
    List<Game> games = new ArrayList();
    try {/*from   w ww  .  j  a va 2s . c  o  m*/
        String host = "http://api.steampowered.com/";
        String path = "IPlayerService/GetOwnedGames/v0001/";
        String key = "?key=06326BE3F53F72F8C6EF31C158FBACD7";
        String id = "&steamid=" + steamId;
        String include = "&include_appinfo=1";
        String format = "&format=json";
        urlString = host + path + key + id + include + format;

        URL url = new URL(urlString);

        ObjectMapper mapper = new ObjectMapper();
        Map<String, Object> JSONMap = mapper.readValue(url, Map.class);

        Map response = (Map) JSONMap.get("response");

        List<Map> gameMaps = (List<Map>) response.get("games");
        if (gameMaps != null) {
            for (Map map : gameMaps) {
                Game game = new Game();
                int appid = (int) map.get("appid");

                game.setAppid(appid);

                String name = (String) map.get("name");
                game.setName(name);

                String imgURL = ((String) map.get("img_icon_url"));
                imgURL = "http://media.steampowered.com/steamcommunity/public/images/apps/" + game.getAppid()
                        + imgURL + ".jpg";
                game.setImg_icon_url(imgURL);

                imgURL = (String) map.get("img_logo_url");
                imgURL = "http://media.steampowered.com/steamcommunity/public/images/apps/" + game.getAppid()
                        + "/" + imgURL + ".jpg";
                game.setImg_logo_url(imgURL);

                if (map.get("playtime_2weeks") != null) {
                    int playtime_2weeks = (int) map.get("playtime_2weeks");
                    game.setPlaytime_2weeks(String.valueOf(playtime_2weeks));
                }
                games.add(game);
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(GetOwnedGames.class.getName()).log(Level.SEVERE, null, ex);
    }

    return games;
}

From source file:com.redhat.ipaas.api.v1.rest.ReadApiClientDataTest.java

private static ObjectMapper getObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new Jdk8Module());
    return objectMapper;
}

From source file:org.trustedanalytics.user.common.UaaProblemReader.java

public static UaaProblem read(HttpStatusCodeException e) {
    ObjectMapper objectMapper = new ObjectMapper();
    try {// w w  w . j a  v a  2 s  .c  o  m
        return objectMapper.readValue(e.getResponseBodyAsString(), UaaProblem.class);
    } catch (IOException e1) {
        LOGGER.error(e1);
        return null;
    }
}

From source file:com.ibm.dgaasx.utils.JSONUtils.java

public static String writeValue(Object object) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setDateFormat(getSDFISO8601());
    return mapper.writeValueAsString(object);
}

From source file:com.pacoworks.cardframework.api.factories.system.SystemFactory.java

public static BasePhaseSystem create(CardgameFramework.CardgameFrameworkComponent injector, @NonNull File file)
        throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    CFWSystem cfwSystem = mapper.readValue(file, CFWSystem.class);
    return create(injector, cfwSystem);
}

From source file:io.fabric8.devops.projects.finder.gogs.JsonHelper.java

/**
 * Creates a configured Jackson object mapper for parsing JSON
 *//*from w w w.  j  a  v  a  2s .com*/
public static ObjectMapper createObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    return mapper;
}

From source file:com.xvdiff.infinity.utils.Mapper.java

public static ObjectMapper getInstance() {
    if (MAPPER == null) {
        MAPPER = new ObjectMapper();
        MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    }/*ww  w. ja  va2 s . co  m*/

    return MAPPER;
}

From source file:org.apache.batchee.jackson.Jacksons.java

public static ObjectMapper newMapper(final String config) {
    final ObjectMapper mapper = new ObjectMapper();
    if (config != null) {
        final String deserializationName = DeserializationFeature.class.getSimpleName();
        final String serializationName = SerializationFeature.class.getSimpleName();
        final String mapperName = MapperFeature.class.getSimpleName();
        for (final String conf : config.split(",")) {
            final String[] parts = conf.split("=");
            parts[0] = parts[0].trim();//w  w w.j a  v a2s .  c  o m
            parts[1] = parts[1].trim();

            if (parts[0].startsWith(deserializationName)) {
                mapper.configure(
                        DeserializationFeature.valueOf(parts[0].substring(deserializationName.length() + 1)),
                        Boolean.parseBoolean(parts[1]));
            } else if (parts[0].startsWith(serializationName)) {
                mapper.configure(
                        SerializationFeature.valueOf(parts[0].substring(serializationName.length() + 1)),
                        Boolean.parseBoolean(parts[1]));
            } else if (parts[0].startsWith(mapperName)) {
                mapper.configure(MapperFeature.valueOf(parts[0].substring(mapperName.length() + 1)),
                        Boolean.parseBoolean(parts[1]));
            } else {
                throw new IllegalArgumentException("Ignored config: " + conf);
            }
        }
    }
    return mapper;
}

From source file:edu.ub.ir.oof1.Util.JSONUtil.java

public static String modelToJsonObj(AbstractModel _model) {
    String out = "";

    try {// w ww.j a v  a 2  s . c om
        ObjectMapper mapper = new ObjectMapper();
        out = mapper.writeValueAsString(_model);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return out;
}

From source file:org.envirocar.json.JsonUtil.java

public static Map<?, ?> createJson(InputStream input) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.readValue(input, Map.class);
}