Search in sources :

Example 1 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project syndesis-qe by syndesisio.

the class AbstractStep method generateStepAction.

// Small hack -> the Action doesn't provide setters for input/output data shape
public Action generateStepAction(Action action, ConnectorDescriptor connectorDescriptor) {
    ObjectMapper mapper = new ObjectMapper().registerModules(new Jdk8Module());
    Action ts = null;
    try {
        JSONObject json = new JSONObject(mapper.writeValueAsString(action));
        JSONObject inputDataType = new JSONObject(mapper.writeValueAsString(connectorDescriptor.getInputDataShape().get()));
        JSONObject outputDataType = new JSONObject(mapper.writeValueAsString(connectorDescriptor.getOutputDataShape().get()));
        JSONArray propertyDefinitionSteps = new JSONArray(mapper.writeValueAsString(connectorDescriptor.getPropertyDefinitionSteps()));
        json.getJSONObject("descriptor").put("inputDataShape", inputDataType);
        json.getJSONObject("descriptor").put("outputDataShape", outputDataType);
        json.getJSONObject("descriptor").put("propertyDefinitionSteps", propertyDefinitionSteps);
        ts = Json.reader().forType(Action.class).readValue(json.toString());
    } catch (IOException ex) {
        log.error("Error: " + ex);
    }
    return ts;
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) Action(io.syndesis.common.model.action.Action) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project ninja by ninjaframework.

the class ObjectMapperProvider method get.

@Override
public ObjectMapper get() {
    ObjectMapper objectMapper = new ObjectMapper();
    // Afterburner optimizes performance of Pojo to Json mapper
    objectMapper.registerModule(new AfterburnerModule());
    // Java 8 data type
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerModule(new Jdk8Module());
    // Joda
    objectMapper.registerModule(new JodaModule());
    return objectMapper;
}
Also used : AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project Rosetta by HubSpot.

the class StoredAsJsonTest method setup.

@Before
public void setup() {
    Rosetta.addModule(new Jdk8Module());
    bean = new StoredAsJsonBean();
    inner = new InnerBean();
    inner.setStringProperty("value");
    ConcreteStoredAsJsonTypeInfo concrete = new ConcreteStoredAsJsonTypeInfo();
    concrete.setGeneralValue("General");
    concrete.setConcreteValue("internal");
    typeInfoBean = concrete;
}
Also used : ConcreteStoredAsJsonTypeInfo(com.hubspot.rosetta.beans.StoredAsJsonTypeInfoBean.ConcreteStoredAsJsonTypeInfo) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) InnerBean(com.hubspot.rosetta.beans.InnerBean) SetStoredAsJsonBean(com.hubspot.rosetta.beans.SetStoredAsJsonBean) OptionalStoredAsJsonBean(com.hubspot.rosetta.beans.OptionalStoredAsJsonBeanIF.OptionalStoredAsJsonBean) StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) MapStoredAsJsonBean(com.hubspot.rosetta.beans.MapStoredAsJsonBean) NestedStoredAsJsonBean(com.hubspot.rosetta.beans.NestedStoredAsJsonBean) ListStoredAsJsonBean(com.hubspot.rosetta.beans.ListStoredAsJsonBeanIF.ListStoredAsJsonBean) PolymorphicStoredAsJsonBean(com.hubspot.rosetta.beans.PolymorphicStoredAsJsonBean) Before(org.junit.Before)

Example 4 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project immutables by immutables.

the class IdAnnotationModuleTest method mappers.

static List<ObjectMapper> mappers() {
    ObjectMapper template = new ObjectMapper().registerModule(new Jdk8Module()).registerModule(new GuavaModule()).registerModule(new JavaTimeModule());
    ObjectMapper mapper1 = template.copy().registerModule(new IdAnnotationModule());
    ObjectMapper mapper2 = template.copy().registerModule(IdAnnotationModule.fromPredicate(m -> ((AnnotatedElement) m).isAnnotationPresent(Criteria.Id.class)));
    ObjectMapper mapper3 = template.copy().registerModule(IdAnnotationModule.fromAnnotation(Criteria.Id.class));
    return Arrays.asList(mapper1, mapper2, mapper3);
}
Also used : Person(org.immutables.criteria.personmodel.Person) Arrays(java.util.Arrays) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) Criteria(org.immutables.criteria.Criteria) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Checkers.check(org.immutables.check.Checkers.check) PersonGenerator(org.immutables.criteria.personmodel.PersonGenerator) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) JavaBean1(org.immutables.criteria.javabean.JavaBean1) ImmutablePerson(org.immutables.criteria.personmodel.ImmutablePerson) MethodSource(org.junit.jupiter.params.provider.MethodSource) AnnotatedElement(java.lang.reflect.AnnotatedElement) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) AnnotatedElement(java.lang.reflect.AnnotatedElement) Criteria(org.immutables.criteria.Criteria) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule)

Example 5 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project Anserini by castorini.

the class BackgroundLinkingTopicReader method extractArticlePlainText.

// Note that there's code duplication here with the WashingtonPostCollection. We can't just call a method there
// because the version of the code inside WashingtonPostCollection.Document modifies internal state (e.g., "kicker"
// and "caption"). Haven't thought of a good solution for this yet.
private static String extractArticlePlainText(String record) {
    WashingtonPostCollection.Document.WashingtonPostObject wapoObj;
    ObjectMapper mapper = new ObjectMapper();
    try {
        wapoObj = mapper.disable(// Ignore unrecognized properties
        DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).registerModule(// Deserialize Java 8 Optional: http://www.baeldung.com/jackson-optional
        new Jdk8Module()).readValue(record, WashingtonPostCollection.Document.WashingtonPostObject.class);
    } catch (IOException e) {
        // Something is wrong... abort!
        throw new RuntimeException(e);
    }
    StringBuilder contentBuilder = new StringBuilder();
    contentBuilder.append(wapoObj.getTitle()).append("\n");
    wapoObj.getContents().ifPresent(contents -> {
        for (WashingtonPostCollection.Document.WashingtonPostObject.Content contentObj : contents) {
            if (contentObj == null)
                continue;
            if (contentObj.getType().isPresent() && contentObj.getContent().isPresent()) {
                contentObj.getType().ifPresent(type -> {
                    contentObj.getContent().ifPresent(content -> {
                        if (WashingtonPostCollection.Document.CONTENT_TYPE_TAG.contains(type)) {
                            contentBuilder.append(Jsoup.parse(content).text()).append("\n");
                        }
                    });
                });
            }
            contentObj.getFullCaption().ifPresent(caption -> {
                String fullCaption = contentObj.getFullCaption().get();
                contentBuilder.append(Jsoup.parse(fullCaption).text()).append("\n");
            });
        }
    });
    return contentBuilder.toString();
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) WashingtonPostCollection(io.anserini.collection.WashingtonPostCollection) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)110 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)87 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)39 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)24 IOException (java.io.IOException)16 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)10 ParameterNamesModule (com.fasterxml.jackson.module.paramnames.ParameterNamesModule)9 Test (org.junit.Test)9 Bean (org.springframework.context.annotation.Bean)9 JSONObject (org.json.JSONObject)8 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)7 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 MetricRegistry (com.codahale.metrics.MetricRegistry)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)5 Action (io.syndesis.common.model.action.Action)5 Test (org.junit.jupiter.api.Test)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Provides (com.google.inject.Provides)4