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.novamedia.novamail.jobserver.rest.ObjectMapperProvider.java

private static ObjectMapper createDefaultMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper.enable(SerializationFeature.INDENT_OUTPUT);

    return mapper;
}

From source file:Main.java

public static <T> T convertObjectFromMap(Map<String, Object> map, String key, Class<T> tClass) {
    if (map == null)
        return null;
    Object obj = map.get(key);/*from w  ww.  jav a 2  s  . co m*/
    String json = null;
    if (obj != null)
        json = serilizeJavaObject(obj);
    else
        return null;

    ObjectMapper mapper = new ObjectMapper();

    T returnVal = null;
    try {
        returnVal = (T) mapper.readValue(json, tClass);
    } catch (JsonParseException 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 returnVal;
}

From source file:com.mapr.data.sputnik.config.JSONConfigReader.java

public static String getJsonConfig(Object o) {
    ObjectMapper mapper = new ObjectMapper();
    String json = null;//from  www.  ja v a2s  .  co m
    try {
        json = mapper.writeValueAsString(o);
    } catch (JsonProcessingException ex) {
        log.warn("Error parsing object into json", ex);
    }
    return json;
}

From source file:edu.usd.btl.toolTree.OntoToTree.java

public static String getOntoJson() throws Exception {
    ObjectMapper treeMapper = new ObjectMapper(); //create new Jackson Mapper
    OntologyFileRead ontFileRead = new OntologyFileRead();
    ArrayList<edu.usd.btl.ontology.BioPortalElement> nodeList = ontFileRead
            .readFile(".\\ontology_files\\EDAM_1.3.owl");

    //write nodelist to JSON string
    ObjectWriter treeWriter = treeMapper.writer().withDefaultPrettyPrinter();
    String edamJSON = treeMapper.writeValueAsString(nodeList);
    System.out.println("**** EDAM ONTOLOGY JSON ****" + edamJSON);

    return edamJSON;
}

From source file:test.SemanticConverter2.java

public static void main(String[] args) throws JAXBException {

    SemanticConverter2 ri = new SemanticConverter2();

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    RegisterContextRequest rcr = new RegisterContextRequest();
    try {/* ww  w  .  ja va  2  s  .co  m*/
        rcr = objectMapper.readValue(ri.NGSI_FILE, RegisterContextRequest.class);
    } catch (Exception e) {

    }
    rcr.setTimestamp(Instant.now());
    ri.createJenaModel(rcr);

    //        //hMap.put("class", "OnDeviceResource"); 
    ////        hMap.put("class", new String[]{"ResourceService"});
    //        hMap.put("class", new String[]{"VirtualEntity"});
    ////        hMap.put("hasID", new String[]{"Resource_1"});
    //        hMap.put("hasID", new String[]{"VirtualEntity_1"});
    //        hMap.put("hasAttributeType", new String[]{"http://purl.oclc.org/NET/ssnx/qu/quantity#temperature"});     
    ////        hMap.put("isHostedOn", "PloggBoard_49_BA_01_light");
    ////        hMap.put("hasType", "Sensor");
    ////        hMap.put("hasName", "lightsensor49_BA_01");
    ////        hMap.put("isExposedThroughService", "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#49_BA_01_light_sensingService");
    ////        hMap.put("hasTag", "light sensor 49,1st,BA,office");
    //        hMap.put("hasLatitude", new String[]{"51.243455"});
    ////        hMap.put("hasGlobalLocation", "http://www.geonames.org/2647793/");
    ////        hMap.put("hasResourceID", "Resource_53_BA_power_sensor");
    ////        hMap.put("hasLocalLocation", "http://www.surrey.ac.uk/ccsr/ontologies/LocationModel.owl#U49");
    //        hMap.put("hasAltitude", new String[]{""});
    //        hMap.put("hasLongitude", new String[]{"-0.588088"});
    ////        hMap.put("hasTimeOffset", "20");
    //
    //        //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#";
    //        //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/VirtualEntityModel.owl#";
    //        //ri.ONT_FILE = "web/IoTA-Models/VirtualEntityModel.owl";
    //        ri.createJenaModel(hMap);
}

From source file:helper.SerializationHelper.java

public static String serializeGridTopology(ActorTopology topology) {
    ObjectMapper mapper = new ObjectMapper();
    Writer strWriter = new StringWriter();
    try {//ww w . java 2 s  .c o  m
        mapper.writeValue(strWriter, topology);
    } catch (Exception e) {
        System.out.println(e);
    }
    return strWriter.toString();
}

From source file:es.logongas.iothome.agent.ConfigLoader.java

public static Config getConfig(String fileName) {
    Config config;/* w  ww  . ja v  a 2  s  . c om*/
    InputStream inputStream = null;
    try {
        ObjectMapper objectMapper = new ObjectMapper();

        inputStream = new BufferedInputStream(new FileInputStream(fileName));
        config = (Config) objectMapper.readValue(inputStream, Config.class);

        return config;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        try {
            if (inputStream != null) {
                inputStream.close();
            }
        } catch (IOException ex) {
            Logger.getLogger(Storage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.dougtest.restTest.getJsonInfo.java

public static JsonNode retrieveResourceFromResponse(final HttpResponse response) throws IOException {
    final String jsonFromResponse = EntityUtils.toString(response.getEntity());
    final ObjectMapper mapper = new ObjectMapper();
    JsonNode root = mapper.readTree(jsonFromResponse);
    return root;/*w  ww. j a va 2s  .c o m*/
}

From source file:com.shampan.util.MongoID.java

@JsonCreator
public static String fromJSON(String val) throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    MongoID a = mapper.readValue(val, MongoID.class);
    return a.get$oid();
}

From source file:com.sitewhere.hbase.common.MarshalUtils.java

/**
 * Marshal an object to a JSON string.//from w  w w.  ja  v a2  s  .c o m
 * 
 * @param object
 * @return
 * @throws SiteWhereException
 */
public static byte[] marshalJson(Object object) throws SiteWhereException {
    ObjectMapper mapper = new ObjectMapper();
    try {
        return mapper.writeValueAsBytes(object);
    } catch (JsonProcessingException e) {
        throw new SiteWhereException("Could not marshal device as JSON.", e);
    }
}