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

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

Introduction

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

Prototype

@SuppressWarnings("resource")
public String writeValueAsString(Object value) throws JsonProcessingException 

Source Link

Document

Method that can be used to serialize any Java value as a String.

Usage

From source file:demo.RxJavaTransformer.java

private static String processData(List<String> data) {

    if (data == null || data.size() == 0)
        return "";

    //start time to find out much time it takes to process data
    Long processingstarttime = System.currentTimeMillis();

    // filter the stream based on number of parameters. It should be 17
    List<String> filtereddata = filterData(data);

    // get the cell start and end information for each event and store it as EventData
    List<EventData> transformedData = transformData(filtereddata);

    // get list of all free taxies
    List<FreeTaxiData> freeTaxiesList = get50FreeTaxies(transformedData);

    // reduced transformed data based on "startendid" key which denotes the starting square and ending square
    List<EventDataCollection> eventsDataCollectionList = reducebyCount(transformedData);

    // Find top 10 areas where taxies are traveling the most
    List<RouteData> top10areas = getTop10Areas(eventsDataCollectionList);

    // Find data related to processing time
    List<String> processingInfoList = getProcessingInfo(processingstarttime, eventsDataCollectionList, data);

    totalEventsProcessed = totalEventsProcessed + data.size();

    // returned all required data as json
    ReturnedData obj = new ReturnedData(processingInfoList, freeTaxiesList, top10areas, totalEventsProcessed);
    ObjectMapper mapper = new ObjectMapper();
    String jsonInString = "";
    try {//w w w .  jav  a 2  s  . c o  m
        jsonInString = mapper.writeValueAsString(obj);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return jsonInString;
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.util.MapConfigHelper.java

public static String getJson(ConfigurationDto config) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString(config);
}

From source file:com.ntsync.android.sync.shared.SyncUtils.java

/**
 * Set Sync-Result for an account./*w  w  w  .ja  v  a 2 s.  c  o m*/
 * 
 * @param accountManager
 * @param account
 * @param syncResult
 */
public static void setSyncResult(AccountManager accountManager, Account account, AccountSyncResult syncResult) {

    String strVal = null;
    if (syncResult != null) {
        ObjectMapper mapper = new ObjectMapper();
        try {
            strVal = mapper.writeValueAsString(syncResult);
        } catch (JsonProcessingException e) {
            LogHelper.logE(TAG, "Could not save AccountSyncResult for account: " + account, e);
        }
    }
    accountManager.setUserData(account, SYNC_STATE, strVal);
}

From source file:com.baasbox.controllers.Root.java

@With(RootCredentialWrapFilter.class)
public static Result counters() throws JsonProcessingException {
    if (!BaasBoxMetric.isActivate())
        return status(SERVICE_UNAVAILABLE, "The metrics service are disabled");
    ObjectMapper mapper = new ObjectMapper()
            .registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
    return ok(mapper.writeValueAsString(BaasBoxMetric.registry.getCounters()));
}

From source file:com.baasbox.controllers.Root.java

@With(RootCredentialWrapFilter.class)
public static Result meters() throws JsonProcessingException {
    if (!BaasBoxMetric.isActivate())
        return status(SERVICE_UNAVAILABLE, "The metrics service are disabled");
    ObjectMapper mapper = new ObjectMapper()
            .registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
    return ok(mapper.writeValueAsString(BaasBoxMetric.registry.getMeters()));
}

From source file:com.baasbox.controllers.Root.java

@With(RootCredentialWrapFilter.class)
public static Result gauges() throws JsonProcessingException {
    if (!BaasBoxMetric.isActivate())
        return status(SERVICE_UNAVAILABLE, "The metrics service are disabled");
    ObjectMapper mapper = new ObjectMapper()
            .registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
    return ok(mapper.writeValueAsString(BaasBoxMetric.registry.getGauges()));
}

From source file:com.baasbox.controllers.Root.java

@With(RootCredentialWrapFilter.class)
public static Result histograms() throws JsonProcessingException {
    if (!BaasBoxMetric.isActivate())
        return status(SERVICE_UNAVAILABLE, "The metrics service is disabled");
    ObjectMapper mapper = new ObjectMapper()
            .registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
    return ok(mapper.writeValueAsString(BaasBoxMetric.registry.getHistograms()));
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.util.MapConfigHelper.java

public static String getStyleSettingsJson(StyleSettingsDto styleSettings) throws ServiceException {
    if (styleSettings == null) {
        return null;
    }//from   ww  w .j a  v  a  2 s .  com
    try {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(styleSettings);
    } catch (IOException e) {
        throw new ServiceException("Parse Exception from Object to json", e);
    }
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.util.MapConfigHelper.java

public static String getVisibilitySettingsJson(VisibilitySettingsDto visibilitySettings)
        throws ServiceException {
    if (visibilitySettings == null) {
        return null;
    }//w w w.j a  va  2  s  . c  o m
    try {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(visibilitySettings);
    } catch (IOException e) {
        throw new ServiceException("Parse Exception from Object to json", e);
    }
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.util.MapConfigHelper.java

public static String getReferenceDataSettingsJson(Map<String, ReferenceDataPropertiesDto> referenceData)
        throws ServiceException {
    if (referenceData == null) {
        return null;
    }//from   w w  w.  j  a  v a  2  s .co  m
    try {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(referenceData);
    } catch (IOException e) {
        throw new ServiceException("Parse Exception from Object to json", e);
    }
}