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.nmdp.service.feature.client.FeatureServiceModule.java

@Provides
@Singleton//from  w w w  .  ja  v a  2 s.  c o m
static FeatureService createFeatureService(@EndpointUrl final String endpointUrl) {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.addMixInAnnotations(Feature.class, FeatureMixIn.class);

    return new RestAdapter.Builder().setEndpoint(endpointUrl).setConverter(new JacksonConverter(objectMapper))
            .build().create(FeatureService.class);
}

From source file:dk.dbc.kafka.logformat.LogEventMapper.java

public LogEventMapper() {
    objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    objectMapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
    objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
}

From source file:com.fpmislata.banco.presentation.Json.Impl.JsonTransformerImplJackson.java

@Override
public String ObjectToJson(Object data) {
    try {// ww w  .  jav  a2s.c  o  m
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.writeValueAsString(data);
    } catch (JsonProcessingException ex) {
        throw new RuntimeException(ex);
    }

}

From source file:org.springframework.rest.documentation.doclet.RestDoclet.java

public static boolean start(RootDoc rootDoc) throws IOException {

    Javadoc api = new JavadocProcessor().process(rootDoc);

    File outputDirectory = getOutputDirectory(rootDoc.options());

    if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs()) {
        throw new IllegalStateException("Failed to create output directory " + outputDirectory);
    }//from   www .  j  ava2 s.co  m

    File file = new File(outputDirectory, "javadoc.json");

    FileWriter writer = new FileWriter(file);

    JsonGenerator generator = new JsonFactory(new ObjectMapper()).createGenerator(writer)
            .useDefaultPrettyPrinter();

    generator.writeObject(api);

    return true;
}

From source file:com.yahoo.elide.utils.coerce.converters.FromMapConverter.java

/**
 * Convert value to Enum.//from   w w  w.  ja v  a 2 s .  c o m
 *
 * @param cls class to convert to
 * @param value value to convert
 * @param <T> object type
 * @return converted object
 */
@Override
public <T> T convert(Class<T> cls, Object value) {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.convertValue(value, cls);
}

From source file:dk.dma.msiproxy.common.util.JsonUtils.java

/**
 * Parses the json data as an entity of the given class
 *
 * @param in the json data to parse/*  w w  w  .  j a v  a 2 s. c o  m*/
 * @param dataClass the class of the data
 * @return the parsed data
 */
public static <T> T fromJson(InputStream in, Class<T> dataClass) throws IOException {
    ObjectMapper jsonMapper = new ObjectMapper();
    return jsonMapper.readValue(in, dataClass);
}

From source file:com.gooddata.dataset.MaqlDmlTest.java

@Test
public void testSerialization() throws Exception {
    final String json = IOUtils.toString(getClass().getResourceAsStream("/dataset/maqlDml.json"), "UTF-8");
    assertThat(new ObjectMapper().writeValueAsString(new MaqlDml("maqlddl")), is(json));
}

From source file:org.dasein.cloud.aws.model.DatabaseProvider.java

public static DatabaseProvider fromFile(String filename, String providerId) throws InternalException {
    try {/*from  w  ww  .j av a 2 s  . co m*/
        ObjectMapper om = new ObjectMapper();
        URL url = om.getClass().getResource(filename);
        DatabaseProvider[] providers = om.readValue(url, DatabaseProvider[].class);
        for (DatabaseProvider provider : providers) {
            if (provider.provider.equalsIgnoreCase(providerId)) {
                return provider;
            }
        }
    } catch (IOException e) {
        throw new InternalException("Unable to read stream", e);
    }
    throw new InternalException("Unable to find " + providerId + " provider configuration in " + filename);
}

From source file:com.netflix.genie.common.util.JsonUtils.java

/**
 * Convert a Java object to a JSON string.
 *
 * @param value The Java object to marshall
 * @return The JSON string/*from w ww.j a  v  a  2s  . c om*/
 * @throws GenieException For any marshalling exception
 */
public static String marshall(final Object value) throws GenieException {
    try {
        final ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(value);
    } catch (final JsonProcessingException jpe) {
        throw new GenieServerException(jpe);
    }
}

From source file:org.apache.hadoop.gateway.util.JsonUtils.java

public static String renderAsJsonString(Map<String, Object> map) {
    String json = null;/*from  ww w .  j a  va 2s  .c  o m*/
    ObjectMapper mapper = new ObjectMapper();

    try {
        // write JSON to a file
        json = mapper.writeValueAsString((Object) map);

    } catch (JsonProcessingException e) {
        LOG.failedToSerializeMapToJSON(map, e);
    }
    return json;
}