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

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

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

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

public static DatabaseProvider fromFile(String filename, String providerId) throws InternalException {
    try {//from  www . j  av a 2 s . c  o 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.tomtom.speedtools.json.Json.java

@Nonnull
private static String toMapper(@Nonnull final ObjectMapper mapper, @Nonnull final Object obj) {
    assert mapper != null;
    assert obj != null;
    try {//from  w  ww.j  a  v a 2 s .  c o  m
        return mapper.writeValueAsString(obj);
    } catch (final JsonMappingException e) {
        LOG.error("toMapper: Map exception {} --> JSON, mapper={}, exception={}",
                obj.getClass().getCanonicalName(), mapper.getClass().getCanonicalName(), e.toString());
    } catch (final IOException e) {
        LOG.error("toMapper: Cannot map {} --> JSON, mapper={}, exception={}",
                obj.getClass().getCanonicalName(), mapper.getClass().getCanonicalName(), e.toString());
    }
    return "";
}

From source file:com.tomtom.speedtools.json.Json.java

@Nullable
private static <T> T fromMapper(@Nonnull final ObjectMapper mapper, @Nonnull final String json,
        @Nonnull final Class<T> type) {
    assert mapper != null;
    assert json != null;
    assert type != null;
    try {//  w ww  .j ava 2 s  . co m
        final StringReader reader = new StringReader(json);
        return mapper.readValue(reader, type);
    } catch (final JsonMappingException e) {
        LOG.error("fromMapper: Cannot map JSON {} --> object, mapper={}, exception={}", json,
                mapper.getClass().getCanonicalName(), e.toString());
    } catch (final IOException e) {
        LOG.error("fromMapper: Cannot map JSON {} --> object, mapper={}, exception={}", json,
                mapper.getClass().getCanonicalName(), e.toString());
    }
    return null;
}

From source file:info.archinnov.achilles.internal.metadata.parsing.EntityParser.java

private void validateEntityAndGetObjectMapper(EntityParsingContext context) {

    Class<?> entityClass = context.getCurrentEntityClass();
    log.debug("Validate entity {}", entityClass.getCanonicalName());

    Validator.validateInstantiable(entityClass);

    ObjectMapper objectMapper = context.getObjectMapperFactory().getMapper(entityClass);
    Validator.validateNotNull(objectMapper, "No Jackson ObjectMapper found for entity '%s'",
            entityClass.getCanonicalName());

    log.debug("Set default object mapper {} for entity {}", objectMapper.getClass().getCanonicalName(),
            entityClass.getCanonicalName());
    context.setCurrentObjectMapper(objectMapper);
}