Search in sources :

Example 51 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project data-transfer-project by google.

the class CalendarContainerResourceTest method verifySerializeDeserialize.

@Test
public void verifySerializeDeserialize() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerSubtypes(CalendarContainerResource.class);
    CalendarEventTime today = new CalendarEventTime(OffsetDateTime.now(), true);
    List<CalendarModel> calendars = ImmutableList.of(new CalendarModel("id1", "name", "description"));
    List<CalendarEventModel> events = ImmutableList.of(new CalendarEventModel("id1", "event1", "A note", null, "Place1", today, today), new CalendarEventModel("id1", "event2", null, ImmutableList.of(new CalendarAttendeeModel("Person", "a@gmail.com", false)), "place 2", today, today));
    ContainerResource data = new CalendarContainerResource(calendars, events);
    String serialized = objectMapper.writeValueAsString(data);
    ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
    Truth.assertThat(deserializedModel).isNotNull();
    Truth.assertThat(deserializedModel).isInstanceOf(CalendarContainerResource.class);
    CalendarContainerResource deserialized = (CalendarContainerResource) deserializedModel;
    Truth.assertThat(deserialized.getCalendars()).hasSize(1);
    Truth.assertThat(deserialized.getEvents()).hasSize(2);
}
Also used : CalendarEventTime(org.dataportabilityproject.types.transfer.models.calendar.CalendarEventModel.CalendarEventTime) ContainerResource(org.dataportabilityproject.types.transfer.models.ContainerResource) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 52 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project crnk-framework by crnk-project.

the class ApprovalIntTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    client = new CrnkClient(getBaseUri().toString());
    client.getObjectMapper().registerModule(new JavaTimeModule());
    HttpAdapter httpAdapter = client.getHttpAdapter();
    httpAdapter.setReceiveTimeout(10000, TimeUnit.SECONDS);
    scheduleRepo = client.getRepositoryForInterface(ScheduleRepository.class);
    approvalRepo = client.getRepositoryForType(ScheduleApprovalProcessInstance.class);
    processTaskRepo = client.getRepositoryForType(ScheduleApprovalProcessInstance.class, ApproveTask.class);
    taskRepo = client.getRepositoryForType(ApproveTask.class);
    approvalRelRepo = client.getRepositoryForType(Schedule.class, ScheduleApprovalProcessInstance.class);
    formRepo = client.getRepositoryForType(ApproveForm.class);
}
Also used : CrnkClient(io.crnk.client.CrnkClient) HttpAdapter(io.crnk.client.http.HttpAdapter) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Schedule(io.crnk.test.mock.models.Schedule) ScheduleRepository(io.crnk.test.mock.repository.ScheduleRepository) ScheduleApprovalProcessInstance(io.crnk.activiti.example.model.ScheduleApprovalProcessInstance) ApproveForm(io.crnk.activiti.example.model.ApproveForm) ApproveTask(io.crnk.activiti.example.model.ApproveTask) Before(org.junit.Before)

Example 53 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project crnk-framework by crnk-project.

the class ApprovalTestApplication method initObjectMapper.

private void initObjectMapper(CrnkFeature feature) {
    ObjectMapper objectMapper = feature.getObjectMapper();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.findAndRegisterModules();
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 54 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project drools by kiegroup.

the class DMNRuntimeTypesTest method testOneOfEachType.

@Test
public void testOneOfEachType() throws Exception {
    final DMNRuntime runtime = createRuntime("OneOfEachType.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_4f5608e9-4d74-4c22-a47e-ab657257fc9c", "OneOfEachType");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    if (!isTypeSafe()) {
        context.set("InputString", "John Doe");
        context.set("InputNumber", BigDecimal.ONE);
        context.set("InputBoolean", true);
        context.set("InputDTDuration", Duration.parse("P1D"));
        context.set("InputYMDuration", Period.parse("P1M"));
        context.set("InputDateAndTime", LocalDateTime.of(2020, 4, 2, 9, 0));
        context.set("InputDate", LocalDate.of(2020, 4, 2));
        context.set("InputTime", LocalTime.of(9, 0));
    } else {
        JsonMapper mapper = JsonMapper.builder().addModule(new JavaTimeModule()).build();
        final String JSON = "{\n" + "    \"InputBoolean\": true,\n" + "    \"InputDTDuration\": \"P1D\",\n" + "    \"InputDate\": \"2020-04-02\",\n" + "    \"InputDateAndTime\": \"2020-04-02T09:00:00\",\n" + "    \"InputNumber\": 1,\n" + "    \"InputString\": \"John Doe\",\n" + "    \"InputTime\": \"09:00\",\n" + "    \"InputYMDuration\": \"P1M\"\n" + "}";
        Class<?> inputSetClass = getStronglyClassByName(dmnModel, "InputSet");
        FEELPropertyAccessible inputSet = (FEELPropertyAccessible) mapper.readValue(JSON, inputSetClass);
        context = new DMNContextFPAImpl(inputSet);
    }
    final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
    LOG.debug("{}", dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    assertThat(dmnResult.getDecisionResultByName("DecisionString").getResult(), is("Hello, John Doe"));
    assertThat(dmnResult.getDecisionResultByName("DecisionNumber").getResult(), is(new BigDecimal(2)));
    assertThat(dmnResult.getDecisionResultByName("DecisionBoolean").getResult(), is(false));
    assertThat(dmnResult.getDecisionResultByName("DecisionDTDuration").getResult(), is(Duration.parse("P2D")));
    assertThat(dmnResult.getDecisionResultByName("DecisionYMDuration").getResult(), is(ComparablePeriod.parse("P2M")));
    assertThat(dmnResult.getDecisionResultByName("DecisionDateAndTime").getResult(), is(LocalDateTime.of(2020, 4, 2, 10, 0)));
    assertThat(dmnResult.getDecisionResultByName("DecisionDate").getResult(), is(LocalDate.of(2020, 4, 3)));
    assertThat(dmnResult.getDecisionResultByName("DecisionTime").getResult(), is(LocalTime.of(10, 0)));
    if (isTypeSafe()) {
        FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
        Map<String, Object> allProperties = outputSet.allFEELProperties();
        assertThat(allProperties.get("DecisionString"), is("Hello, John Doe"));
        assertThat(allProperties.get("DecisionNumber"), is(new BigDecimal(2)));
        assertThat(allProperties.get("DecisionBoolean"), is(false));
        assertThat(allProperties.get("DecisionDTDuration"), is(Duration.parse("P2D")));
        assertThat(allProperties.get("DecisionYMDuration"), is(ComparablePeriod.parse("P2M")));
        assertThat(allProperties.get("DecisionDateAndTime"), is(LocalDateTime.of(2020, 4, 2, 10, 0)));
        assertThat(allProperties.get("DecisionDate"), is(LocalDate.of(2020, 4, 3)));
        assertThat(allProperties.get("DecisionTime"), is(LocalTime.of(10, 0)));
    }
}
Also used : DMNContextFPAImpl(org.kie.dmn.core.impl.DMNContextFPAImpl) DMNResult(org.kie.dmn.api.core.DMNResult) FEELPropertyAccessible(org.kie.dmn.api.core.FEELPropertyAccessible) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) BigDecimal(java.math.BigDecimal) JsonMapper(com.fasterxml.jackson.databind.json.JsonMapper) DMNModel(org.kie.dmn.api.core.DMNModel) BaseVariantTest(org.kie.dmn.core.BaseVariantTest) DMNRuntimeTest(org.kie.dmn.core.DMNRuntimeTest) Test(org.junit.Test) DMNDecisionServicesTest(org.kie.dmn.core.v1_2.DMNDecisionServicesTest)

Example 55 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project cas by apereo.

the class CasObjectMapperFactory method applyDefaultConfiguration.

@Override
protected void applyDefaultConfiguration(final ObjectMapper om) {
    super.applyDefaultConfiguration(om);
    om.registerModule(new JavaTimeModule());
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)

Aggregations

JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)81 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)65 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)17 Test (org.junit.Test)9 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 ParameterNamesModule (com.fasterxml.jackson.module.paramnames.ParameterNamesModule)7 Bean (org.springframework.context.annotation.Bean)7 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)6 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)5 Before (org.junit.Before)4 Primary (org.springframework.context.annotation.Primary)4 StdDateFormat (com.fasterxml.jackson.databind.util.StdDateFormat)3 LocalDateSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer)3 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)3 IOException (java.io.IOException)3 MetricsModule (com.codahale.metrics.json.MetricsModule)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)2 Module (com.fasterxml.jackson.databind.Module)2 PropertyNamingStrategy (com.fasterxml.jackson.databind.PropertyNamingStrategy)2 JsonMapper (com.fasterxml.jackson.databind.json.JsonMapper)2