Search in sources :

Example 26 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project kylo by Teradata.

the class TriggerFeedTest method testFeedDependencyResultsExecutionContext.

@Test
public void testFeedDependencyResultsExecutionContext() {
    FeedDependencyDeltaResults deltaResults = new FeedDependencyDeltaResults();
    List<String> feedNames = new ArrayList<>();
    feedNames.add("category.feed_a");
    feedNames.add("category.feed_b");
    deltaResults.setDependentFeedNames(feedNames);
    Map<String, FeedDependencyDeltaResults.FeedJobExecutionData> jobData = new HashMap<>();
    feedNames.stream().forEach(feedName -> {
        Map<String, Object> executionContext = new HashMap<>();
        executionContext.put("param1", "test");
        executionContext.put("export.kylo.param2", "test2");
        deltaResults.addFeedExecutionContext(feedName, new Long(1), DateTime.now(), DateTime.now(), executionContext);
    });
    String executionContextKeys = "export.kylo, export.test, test2 ";
    List<String> list = new ArrayList<String>(Arrays.asList(executionContextKeys.trim().split("\\s*,\\s*")));
    deltaResults.reduceExecutionContextToMatchingKeys(list);
    // assert just the 1 property got sent to the execution context
    Assert.assertEquals(1, deltaResults.getLatestFeedJobExecutionContext().get(feedNames.get(0)).getExecutionContext().size());
    // validate JSON transform
    ObjectMapper MAPPER = new ObjectMapper();
    MAPPER.registerModule(new JodaModule());
    MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
    MAPPER.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    try {
        String value = MAPPER.writeValueAsString(deltaResults);
        Assert.assertNotNull(value);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) ArrayList(java.util.ArrayList) FeedDependencyDeltaResults(com.thinkbiganalytics.metadata.api.op.FeedDependencyDeltaResults) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 27 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project opsgenie-configuration-backup by opsgenie.

the class DeprecatedPolicyImporter method readJson.

private DeprecatedAlertPolicy readJson(String alertPolicyJson) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JodaModule());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    mapper.setDateFormat(sdf);
    return mapper.readValue(alertPolicyJson, DeprecatedAlertPolicy.class);
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) SimpleDateFormat(java.text.SimpleDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 28 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project opsgenie-configuration-backup by opsgenie.

the class IntegrationImporter method readJson.

private IntegrationConfig readJson(String entityJson) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JodaModule());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    mapper.setDateFormat(sdf);
    return mapper.readValue(entityJson, IntegrationConfig.class);
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) SimpleDateFormat(java.text.SimpleDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 29 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project oap by oaplatform.

the class Binder method initialize.

private static ObjectMapper initialize(ObjectMapper mapper, boolean defaultTyping, boolean nonNullInclusion, boolean skipInputNulls) {
    if (mapper instanceof XmlMapper) {
        ((XmlMapper) mapper).setDefaultUseWrapper(false);
        ((XmlMapper) mapper).configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
    }
    AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
    mapper.getDeserializationConfig().with(introspector);
    mapper.getSerializationConfig().with(introspector);
    mapper.registerModule(new AfterburnerModule());
    mapper.registerModule(new Jdk8Module().configureAbsentsAsNulls(true));
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new ExtModule());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.DEFAULT));
    mapper.enable(DeserializationFeature.USE_LONG_FOR_INTS);
    mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
    mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
    mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    // todo remove after kernel cleanup
    mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
    if (skipInputNulls)
        mapper.setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SKIP));
    if (!nonNullInclusion)
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    modules.forEach(mapper::registerModule);
    if (defaultTyping)
        mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    return mapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ParameterNamesModule(com.fasterxml.jackson.module.paramnames.ParameterNamesModule) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) ExtModule(oap.json.ext.ExtModule)

Example 30 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project kylo by Teradata.

the class JerseyConfig method createJsonProvider.

private JacksonJaxbJsonProvider createJsonProvider() {
    final JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    final ObjectMapper om = new ObjectMapper();
    om.registerModule(new JodaModule());
    om.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
    om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    provider.setMapper(om);
    return provider;
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)45 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)37 Test (org.junit.Test)15 IOException (java.io.IOException)14 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)7 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Resource (org.springframework.core.io.Resource)6 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)5 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)5 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)5 SimpleDateFormat (java.text.SimpleDateFormat)4 Bean (org.springframework.context.annotation.Bean)4 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 Primary (org.springframework.context.annotation.Primary)3 MetricsModule (com.codahale.metrics.json.MetricsModule)2 PropertyNamingStrategy (com.fasterxml.jackson.databind.PropertyNamingStrategy)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)2 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)2