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

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

Introduction

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

Prototype

@SuppressWarnings("unchecked")
    public <T> T readValue(byte[] src, JavaType valueType)
            throws IOException, JsonParseException, JsonMappingException 

Source Link

Usage

From source file:com.mgatelabs.bytemapper.support.definitions.FormatDefinition.java

public static FormatDefinition load(File input) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    FormatDefinition def;/*from   www. j a  v a 2 s .  c om*/
    def = mapper.readValue(input, FormatDefinition.class);
    def.sanity();
    return def;
}

From source file:es.us.isa.aml.parsers.agreements.yaml.ParserYAMLUtil.java

public static String convertToYaml(String jsonContent) {
    Map<String, String> propertyMap = new HashMap<String, String>();
    ObjectMapper mapper = new ObjectMapper();
    try {/*from  w  ww .j  av a 2  s .  c  o m*/
        propertyMap = mapper.readValue(jsonContent, new TypeReference<HashMap<String, Object>>() {
        });
    } catch (IOException ex) {
        Logger.getLogger(ParserYAMLUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
    Yaml yaml = new Yaml();
    String output = yaml.dump(propertyMap);
    return output;
}

From source file:com.boundary.sdk.snmp.metric.Pollers.java

public static Pollers load(String resource) throws URISyntaxException {
    Pollers instance = new Pollers();

    ClassLoader classLoader = instance.getClass().getClassLoader();
    URL url = classLoader.getResource(resource);
    File file = new File(url.toURI());

    ObjectMapper mapper = new ObjectMapper();

    try {//from w w  w  .j  a v  a 2  s.  c  o m
        instance = mapper.readValue(file, Pollers.class);
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return instance;
}

From source file:com.brimarx.servicebox.backend.BackendFactory.java

private static Backend buildCassandra(String connectivity) {
    try {/*from ww  w.j a v a 2 s .c  om*/
        if (connectivity == null || connectivity.trim().isEmpty())
            connectivity = DEFAULT_BE_OPTS_CASSANDRA;
        ObjectMapper om = new ObjectMapper();
        CassandraConfig cfg = om.readValue(connectivity, CassandraConfig.class);
        return new CassandraBackend(cfg);
    } catch (IOException e) {
        throw new IllegalArgumentException("invalid backend connectivity '" + connectivity + "' : " + e, e);
    }
}

From source file:com.sdl.odata.renderer.util.PrettyPrinter.java

/**
 * Pretty-print a given Json./*from w w  w  .  j  a  v a 2  s . co  m*/
 *
 * @param json The not-formatted Json.
 * @return The pretty-printed Json
 * @throws IOException
 */
public static String prettyPrintJson(String json) throws IOException {

    ObjectMapper objectMapper = new ObjectMapper();
    Object jsonObject = objectMapper.readValue(json, Object.class);

    return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
}

From source file:com.shampan.db.collections.fragment.common.Comment.java

public static Comment getCommentInfo(String jsonContent) {
    Comment commentInfo = null;// w w w .  ja v a2 s  . co  m
    try {
        ObjectMapper mapper = new ObjectMapper();
        commentInfo = mapper.readValue(jsonContent, Comment.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return commentInfo;
}

From source file:com.shampan.db.collections.fragment.status.Comment.java

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

From source file:de.javagl.jgltf.model.io.JsonUtils.java

/**
 * Creates a formatted (pretty-printed, indented) representation of
 * the given JSON string. The details of the formatting are not 
 * specified. If there is any error during this process, then a 
 * warning will be printed and the given string will be returned.
 * /*from   w w w  .  j  a  v a2s  .c om*/
 * @param jsonString The input JSON string
 * @return The formatted JSON string
 */
public static String format(String jsonString) {
    ObjectMapper mapper = new ObjectMapper();
    try {
        Object object = mapper.readValue(jsonString, Object.class);
        String formattedJsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
        return formattedJsonString;
    } catch (IOException e) {
        logger.warning(e.getMessage());
        return jsonString;
    }
}

From source file:net.landora.justintv.JustinTVAPI.java

public static List<JustinArchive> readArchives(String channelName, int offset, int maxNumber) throws Exception {

    String url = String.format("http://api.justin.tv/api/channel/archives/%s.json?offest=%d&limit=%d",
            channelName, offset, Math.min(100, maxNumber));

    InputStream stream = openURL(url);

    ObjectMapper mapper = new ObjectMapper();

    List<JustinArchive> readValue = mapper.readValue(stream, new TypeReference<List<JustinArchive>>() {
    });//from  w ww . j a  v  a2  s  .  c o m

    return readValue;
}

From source file:it.eng.spagobi.studio.console.model.bo.JsonTemplateGenerator.java

/** populate the ConsoleTemplateModel Object from template*/
public static ConsoleTemplateModel readJson(IFile file) throws CoreException {
    ConsoleTemplateModel objFromJson = null;
    ObjectMapper mapper = new ObjectMapper();
    try {/*  w w w  . j  a  v  a  2  s .  com*/
        objFromJson = mapper.readValue(file.getContents(), ConsoleTemplateModel.class);
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return objFromJson;
}