Search in sources :

Example 21 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project tutorials by eugenp.

the class JacksonDateUnitTest method whenSerializingJava8Date_thenCorrect.

@Test
public void whenSerializingJava8Date_thenCorrect() throws JsonProcessingException {
    final LocalDateTime date = LocalDateTime.of(2014, 12, 20, 2, 30);
    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JSR310Module());
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    final String result = mapper.writeValueAsString(date);
    assertThat(result, containsString("2014-12-20T02:30"));
}
Also used : LocalDateTime(java.time.LocalDateTime) EventWithLocalDateTime(com.baeldung.jackson.date.EventWithLocalDateTime) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) Matchers.containsString(org.hamcrest.Matchers.containsString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 22 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.

the class ElasticSearchIndexUpdater method addOrUpdateIndex.

@Override
public void addOrUpdateIndex(String typeName, Map<String, Object> entity) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JSR310Module());
    String json;
    try {
        json = mapper.writeValueAsString(entity);
        String id = entity.get("id").toString();
        @SuppressWarnings("unused") IndexResponse response = elasticClient.prepareIndex("muikku", typeName, id).setSource(json).execute().actionGet();
    } catch (IOException e) {
        logger.log(Level.WARNING, "Adding to index failed because of exception", e);
    }
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.

the class AbstractUITest method createWorkspaceFolder.

protected WorkspaceFolder createWorkspaceFolder(Long workspaceEntityId, Long parentId, Boolean hidden, Integer orderNumber, String title, String folderType) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    WorkspaceFolder payload = new WorkspaceFolder(null, hidden, orderNumber, null, title, parentId);
    Response response = asAdmin().contentType("application/json").body(payload).post("/test/workspaces/{WORKSPACEENTITYIID}/folders", workspaceEntityId);
    response.then().statusCode(200);
    WorkspaceFolder result = objectMapper.readValue(response.asString(), WorkspaceFolder.class);
    assertNotNull(result);
    assertNotNull(result.getId());
    return result;
}
Also used : Response(com.jayway.restassured.response.Response) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WorkspaceFolder(fi.otavanopisto.muikku.atests.WorkspaceFolder)

Example 24 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.

the class AbstractUITest method createWorkspaceHtmlMaterial.

protected WorkspaceHtmlMaterial createWorkspaceHtmlMaterial(Long workspaceEntityId, Long parentId, String title, String contentType, String html, Long revisionNumber, String assignmentType) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    WorkspaceHtmlMaterial payload = new WorkspaceHtmlMaterial(null, parentId, title, contentType, html, revisionNumber, assignmentType, null);
    Response response = asAdmin().contentType("application/json;charset=UTF-8").body(payload).post("/test/workspaces/{WORKSPACEENTITYIID}/htmlmaterials", workspaceEntityId);
    response.then().statusCode(200);
    WorkspaceHtmlMaterial result = objectMapper.readValue(response.asString(), WorkspaceHtmlMaterial.class);
    assertNotNull(result);
    assertNotNull(result.getId());
    return result;
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceHtmlMaterial(fi.otavanopisto.muikku.atests.WorkspaceHtmlMaterial) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 25 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.

the class AbstractUITest method createWorkspaceDiscussion.

protected Discussion createWorkspaceDiscussion(Long workspaceEntityId, Long groupId, String name) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    Discussion payload = new Discussion(null, name, null, groupId);
    Response response = asAdmin().contentType("application/json").body(payload).post("/test/workspaces/{WORKSPACEENTITYID}/discussiongroups/{GROUPID}/discussions", workspaceEntityId, groupId);
    response.then().statusCode(200);
    Discussion workspaceDiscussion = objectMapper.readValue(response.asString(), Discussion.class);
    assertNotNull(workspaceDiscussion);
    assertNotNull(workspaceDiscussion.getId());
    return workspaceDiscussion;
}
Also used : Response(com.jayway.restassured.response.Response) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) Discussion(fi.otavanopisto.muikku.atests.Discussion) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)55 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 Response (com.jayway.restassured.response.Response)13 OffsetDateTime (java.time.OffsetDateTime)13 CourseStaffMember (fi.otavanopisto.pyramus.rest.model.CourseStaffMember)9 ArrayList (java.util.ArrayList)9 Workspace (fi.otavanopisto.muikku.atests.Workspace)7 Test (org.junit.Test)7 Builder (fi.otavanopisto.muikku.mock.PyramusMock.Builder)6 MockStaffMember (fi.otavanopisto.muikku.mock.model.MockStaffMember)6 AbstractUITest (fi.otavanopisto.muikku.ui.AbstractUITest)6 StaffMember (fi.otavanopisto.pyramus.rest.model.StaffMember)6 Course (fi.otavanopisto.pyramus.rest.model.Course)5 Email (fi.otavanopisto.pyramus.rest.model.Email)5 WebhookPersonCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookPersonCreatePayload)5 TestEnvironments (fi.otavanopisto.muikku.TestEnvironments)4 MockCourseStudent (fi.otavanopisto.muikku.mock.model.MockCourseStudent)4 CourseStudent (fi.otavanopisto.pyramus.rest.model.CourseStudent)4 Person (fi.otavanopisto.pyramus.rest.model.Person)4 Student (fi.otavanopisto.pyramus.rest.model.Student)4