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:org.apache.unomi.itests.TestUtils.java

public static <T> T retrieveResourceFromResponse(HttpResponse response, Class<T> clazz) throws IOException {
    String jsonFromResponse = EntityUtils.toString(response.getEntity());
    ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
            false);//from   w  ww  .  ja  v a 2s . c  om
    return mapper.readValue(jsonFromResponse, clazz);
}

From source file:org.dswarm.xsd2jsonschema.model.test.BaseJSTest.java

@BeforeClass
public static void startUp() throws Exception {
    BaseJSTest.om = new ObjectMapper();
}

From source file:com.shampan.db.collections.fragment.page.AgeRange.java

public static AgeRange getUserInformation(String jsonContent) {
    AgeRange ageInfo = null;// ww  w  .j  a v a  2 s .c  om
    try {
        ObjectMapper mapper = new ObjectMapper();
        ageInfo = mapper.readValue(jsonContent, AgeRange.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return ageInfo;
}

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

public static List<SteamAccount> retrieve(String steamId) {
    String urlString = "";
    List<SteamAccount> friends = new ArrayList();
    try {/* w ww. jav a  2 s. co  m*/
        //http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=06326BE3F53F72F8C6EF31C158FBACD7&steamid=76561197976892493&relationship=all
        String host = "http://api.steampowered.com/";
        String path = "ISteamUser/GetFriendList/v0001/";
        String key = "?key=06326BE3F53F72F8C6EF31C158FBACD7";
        String id = "&steamid=" + steamId;
        String relationship = "&relationship=all";
        urlString = host + path + key + id + relationship;

        URL url = new URL(urlString);

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

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

        if (response != null) {
            List<Map> friendMaps = (List<Map>) response.get("friends");
            if (friendMaps != null) {
                for (Map map : friendMaps) {

                    String steamid = (String) map.get("steamid");
                    SteamAccount friend = GetPlayerSummaries.retrieve(steamid);

                    friend.getOwnedGames();
                    friends.add(friend);
                }
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(GetOwnedGames.class.getName()).log(Level.SEVERE, null, ex);
    }

    return friends;
}

From source file:Main.java

public static String serilizeJavaObject(Object value) {
    ObjectMapper objectMapper = new ObjectMapper();
    String json = null;//  www  . jav a 2  s.  co m
    try {
        json = objectMapper.writeValueAsString(value);
    } catch (JsonGenerationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return json;
}

From source file:com.uimirror.core.framework.rest.util.ObjectMapperFactory.java

public static ObjectMapper getDefaultMapper() {
    return new ObjectMapper().configure(DeserializationFeature.UNWRAP_ROOT_VALUE, FALSE)
            .configure(SerializationFeature.WRAP_ROOT_VALUE, FALSE).enable(SerializationFeature.INDENT_OUTPUT)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .setAnnotationIntrospector(getAnnotationPair());

}

From source file:org.rapidoid.json.JSON.java

private static ObjectMapper mapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return mapper;
}

From source file:com.hpcloud.util.config.Configurations.java

public static Map<String, String> configFor(String keyPrefix, Object source) {
    Map<String, String> config = new HashMap<String, String>();
    buildConfigFor(keyPrefix, config, new ObjectMapper().valueToTree(source));
    return config;
}

From source file:org.opendaylight.alto.core.northbound.route.endpointproperty.impl.EndpointpropertyRouteChecker.java

public static JsonNode checkJsonSyntax(String content) {
    JsonNode jsonContent;//from   w  ww  .  j a va 2  s .  co  m
    ObjectMapper mapper = new ObjectMapper();
    try {
        jsonContent = mapper.readTree(content);
    } catch (IOException e) {
        throw new AltoErrorSyntax();
    }
    if (null == jsonContent) {
        throw new AltoErrorSyntax();
    } else if (jsonContent.isNull()) {
        throw new AltoErrorMissingField(AltoNorthboundRouteEndpointproperty.FIELD_PROPERTIES);
    } else {
        return jsonContent;
    }
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.http.JsonDataFetcher.java

private static JsonNode getJsonRootNode(String json) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.readTree(json);
}