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:info.archinnov.achilles.json.DefaultJacksonMapper.java

private static ObjectMapper defaultJacksonMapper() {
    ObjectMapper defaultMapper = new ObjectMapper();
    defaultMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
    defaultMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    defaultMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    defaultMapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary));
    return defaultMapper;
}

From source file:com.millcreeksoftware.amliclookup.fcclookup.FccLookupHandler.java

/**
 * Gets the FCC data for the provided call sign.
 * /*from   w w w  .  j  a v  a  2  s .  c  o  m*/
 * @param callSign The call sign to lookup.
 * 
 * @return A populated <code>FccLookupData</code>.
 */
public static FccLookupData getFccData(String callSign) {
    FccLookupData fccLookupData = new FccLookupData();

    URL url;
    try {
        url = new URL(FCC_LOOKUP_BASE_URL + callSign);
        ObjectMapper m = new ObjectMapper();
        JsonNode rootNode = m.readValue(url.openStream(), JsonNode.class);

        String status = rootNode.path("status").textValue();
        if (!"OK".equalsIgnoreCase(status)) {
            return fccLookupData;
        }

        fccLookupData.setStatusOK(true);

        JsonNode licensesNode = rootNode.path("Licenses");
        String lastUpdate = licensesNode.path("lastUpdate").asText();
        fccLookupData.setLastUpdate(lastUpdate);

        JsonNode licenseNode = licensesNode.path("License");
        JsonNode arrayNode = licenseNode.path(0);
        String frn = arrayNode.path("frn").asText();
        fccLookupData.setFrn(frn);

        String statusDesc = arrayNode.path("statusDesc").asText();
        fccLookupData.setStatusDesc(statusDesc);

        String expiredDate = arrayNode.path("expiredDate").asText();
        fccLookupData.setExpireDate(expiredDate);

        String licenseId = arrayNode.path("licenseID").asText();
        fccLookupData.setLicenseId(licenseId);

        fccLookupData.setFccUrl(FFC_MORE_INFO_BASE_URL + licenseId);
    } catch (MalformedURLException e) {
        fccLookupData.setStatusOK(false);
        logger.warn("Error looking up call '" + callSign + "'.", e);
    } catch (JsonParseException e) {
        fccLookupData.setStatusOK(false);
        logger.warn("Error looking up call '" + callSign + "'.", e);
    } catch (JsonMappingException e) {
        fccLookupData.setStatusOK(false);
        logger.warn("Error looking up call '" + callSign + "'.", e);
    } catch (IOException e) {
        fccLookupData.setStatusOK(false);
        logger.warn("Error looking up call '" + callSign + "'.", e);
    }

    return fccLookupData;
}

From source file:fr.cph.chicago.parser.JsonParser.java

@NonNull
public static JsonParser getInstance() {
    if (INSTANCE == null) {
        INSTANCE = new JsonParser();
        MAPPER = new ObjectMapper();
    }//from   www  . j  a v a  2 s . co  m
    return INSTANCE;
}

From source file:com.ibm.dgaasx.utils.JSONUtils.java

public static Object readValue(String value, Class<?> clazz) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.readValue(value, clazz);
}

From source file:com.shampan.db.collections.fragment.profile.Town.java

public static Town getHomeTown(String jsonContent) {
    Town town = null;/*from w  w w. ja va2s. c  o  m*/
    try {
        ObjectMapper mapper = new ObjectMapper();
        town = mapper.readValue(jsonContent, Town.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return town;
}

From source file:com.shampan.db.collections.fragment.profile.City.java

public static City getCurrentCity(String jsonContent) {
    City city = null;//from  ww w.ja v a  2s .c o m
    try {
        ObjectMapper mapper = new ObjectMapper();
        city = mapper.readValue(jsonContent, City.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return city;
}

From source file:com.shampan.db.collections.fragment.user.Country.java

public static Country getCountryInfo(String jsonContent) {
    Country countryInfo = null;//from  w ww .  j  a  v  a2s. c om
    try {
        ObjectMapper mapper = new ObjectMapper();
        countryInfo = mapper.readValue(jsonContent, Country.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return countryInfo;
}

From source file:it.jugtorino.one.msvc.way.rabbit.reference.utils.JSONUtils.java

public static byte[] toBytes(Map<String, Object> map) {
    ObjectMapper mapper = new ObjectMapper();
    try {//from  w ww  .  jav  a2 s  .  c om
        return mapper.writeValueAsBytes(map);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.faraox.rest.poc.provider.MyObjectMapperProvider.java

private static ObjectMapper createCombinedObjectMapper() {
    return new ObjectMapper().configure(SerializationFeature.WRAP_ROOT_VALUE, true)
            .configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true)
            .setAnnotationIntrospector(createJaxbJacksonAnnotationIntrospector());
}

From source file:org.hawkular.client.test.utils.JSONHelper.java

public static <T> T load(Class<T> clz, String jsonFile) {
    InputStream is = JSONHelper.class.getResourceAsStream(jsonFile);
    if (is == null) {
        throw new RuntimeException("Can't load " + jsonFile);
    }/*from  ww w  . j  a  v  a 2s .c o m*/
    ObjectMapper mapper = new ObjectMapper();
    try {
        return mapper.readValue(is, clz);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}