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.griddynamics.deming.data.generator.serialization.JsonUtil.java

public static <T> T read(Class<T> tClass, InputStream inputStream) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.readValue(inputStream, tClass);
}

From source file:Main.java

public static String getValueFromJson(String json, String key) {
    String value = "null";
    try {/*from www  .  j  a v  a2s .  c  om*/
        ObjectMapper mapper = new ObjectMapper();
        Map<String, Object> values = mapper.readValue(json, new TypeReference<Map<String, String>>() {
        });
        if (values.containsKey(key)) {
            value = values.get(key).toString();
        }
    } catch (IOException e) {
        System.out.println("Could not parse json: " + json);
    }
    return value;
}

From source file:io.confluent.kafka.schemaregistry.client.rest.entities.requests.RegisterSchemaResponse.java

public static RegisterSchemaResponse fromJson(String json) throws IOException {
    return new ObjectMapper().readValue(json, RegisterSchemaResponse.class);
}

From source file:com.basistech.rosette.dm.json.array.AdmAssert.java

public static ObjectMapper objectMapper() {
    return AnnotatedDataModelArrayModule.setupObjectMapper(new ObjectMapper());
}

From source file:com.shampan.db.collections.fragment.photo.Image.java

public static Image getImageInfo(String jsonContent) {
    Image imageInfo = null;/*from  w w  w . j a v a 2 s .c  om*/
    try {
        ObjectMapper mapper = new ObjectMapper();
        imageInfo = mapper.readValue(jsonContent, Image.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return imageInfo;
}

From source file:io.confluent.kafka.schemaregistry.client.rest.entities.requests.ConfigUpdateRequest.java

public static ConfigUpdateRequest fromJson(String json) throws IOException {
    return new ObjectMapper().readValue(json, ConfigUpdateRequest.class);
}

From source file:local.laer.app.newgenerator.TileBuilder.java

public static String json(Tile tile) {
    try {/*from  w w  w  . ja v  a  2 s  .co  m*/
        return new ObjectMapper().writeValueAsString(tile);
    } catch (JsonProcessingException ex) {
        Logger.getLogger(TileBuilder.class.getName()).log(Level.SEVERE, null, ex);
        throw new RuntimeException(ex);
    }
}

From source file:org.reactivesource.util.JsonParserUtils.java

public static Map<String, Object> jsonObjectToMap(JSONObject jsonObject) {
    notNull(jsonObject, "jsonString can not be null");
    try {//  w  w  w . j  a va 2  s. com
        return new ObjectMapper().readValue(jsonObject.toString(), HashMap.class);
    } catch (IOException e) {
        throw new JSONException("Could not map row entity:" + jsonObject.toString());
    }
}

From source file:io.confluent.kafka.schemaregistry.client.rest.entities.requests.CompatibilityCheckResponse.java

public static CompatibilityCheckResponse fromJson(String json) throws IOException {
    return new ObjectMapper().readValue(json, CompatibilityCheckResponse.class);
}

From source file:bakuposter.gcm.server.POST2GCMessage.java

public static void post(String apiKey, Content content) {

    try {//w w  w  .  j  av a 2  s .c o m
        URL url = new URL("https://android.googleapis.com/gcm/send");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("Authorization", "key=" + apiKey);
        conn.setDoOutput(true);
        ObjectMapper mapper = new ObjectMapper();
        System.out.println(content.getRegistration_ids().get(0));
        DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
        mapper.writeValue(wr, content);
        wr.flush();
        wr.close();
        int responseCode = conn.getResponseCode();
        System.out.println("responseCode = " + responseCode);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}