Search in sources :

Example 11 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project goci by EBISPOT.

the class DepositionSampleDtoTest method testReadSamplesResponse.

@Test
public void testReadSamplesResponse() {
    String json = "{\n" + "  \"_embedded\" : {\n" + "    \"samples\" : [ {\n" + "      \"study_tag\" : \"30237584_1\",\n" + "      \"size\" : 657,\n" + "      \"cases\" : 226,\n" + "      \"controls\" : 431,\n" + "      \"sample_description\" : \"\",\n" + "      \"ancestry_category\" : \"European\",\n" + "      \"ancestry\" : \"\",\n" + "      \"ancestry_description\" : \"\",\n" + "      \"countryRecruitement\" : \"Germany\",\n" + "      \"stage\" : \"Discovery\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d515077dcf21d0001eee22b\"\n" + "        }\n" + "      }\n" + "    }, {\n" + "      \"study_tag\" : \"30237584_1\",\n" + "      \"size\" : 537,\n" + "      \"cases\" : 143,\n" + "      \"controls\" : 394,\n" + "      \"sample_description\" : \"\",\n" + "      \"ancestry_category\" : \"Hispanic or Latin American\",\n" + "      \"ancestry\" : \"Hispanic\",\n" + "      \"ancestry_description\" : \"\",\n" + "      \"countryRecruitement\" : \"Germany\",\n" + "      \"stage\" : \"Discovery\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d515077dcf21d0001eee22b\"\n" + "        }\n" + "      }\n" + "    }, {\n" + "      \"study_tag\" : \"30237584_1\",\n" + "      \"size\" : 263,\n" + "      \"cases\" : 71,\n" + "      \"controls\" : 192,\n" + "      \"sample_description\" : \"\",\n" + "      \"ancestry_category\" : \"European\",\n" + "      \"ancestry\" : \"\",\n" + "      \"ancestry_description\" : \"\",\n" + "      \"countryRecruitement\" : \"Germany\",\n" + "      \"stage\" : \"Replication\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d515077dcf21d0001eee22b\"\n" + "        }\n" + "      }\n" + "    }, {\n" + "      \"study_tag\" : \"30237584_1\",\n" + "      \"size\" : 322,\n" + "      \"cases\" : 83,\n" + "      \"controls\" : 192,\n" + "      \"sample_description\" : \"\",\n" + "      \"ancestry_category\" : \"Hispanic or Latin American\",\n" + "      \"ancestry\" : \"Hispanic\",\n" + "      \"ancestry_description\" : \"\",\n" + "      \"countryRecruitement\" : \"Germany\",\n" + "      \"stage\" : \"Replication\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d515077dcf21d0001eee22b\"\n" + "        }\n" + "      }\n" + "    }, {\n" + "      \"study_tag\" : \"30237584_2\",\n" + "      \"size\" : 920,\n" + "      \"cases\" : 297,\n" + "      \"controls\" : 623,\n" + "      \"sample_description\" : \"\",\n" + "      \"ancestry_category\" : \"European\",\n" + "      \"ancestry\" : \"\",\n" + "      \"ancestry_description\" : \"\",\n" + "      \"countryRecruitement\" : \"Germany\",\n" + "      \"stage\" : \"Discovery\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d515077dcf21d0001eee22b\"\n" + "        }\n" + "      }\n" + "    }, {\n" + "      \"study_tag\" : \"30237584_2\",\n" + "      \"size\" : 859,\n" + "      \"cases\" : 226,\n" + "      \"controls\" : 633,\n" + "      \"sample_description\" : \"\",\n" + "      \"ancestry_category\" : \"Hispanic or Latin American\",\n" + "      \"ancestry\" : \"Hispanic\",\n" + "      \"ancestry_description\" : \"\",\n" + "      \"countryRecruitement\" : \"Germany\",\n" + "      \"stage\" : \"Discovery\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d515077dcf21d0001eee22b\"\n" + "        }\n" + "      }\n" + "    }, {\n" + "      \"study_tag\" : \"30237584_2\",\n" + "      \"size\" : 2417,\n" + "      \"cases\" : 1946,\n" + "      \"controls\" : 471,\n" + "      \"sample_description\" : \"\",\n" + "      \"ancestry_category\" : \"European\",\n" + "      \"ancestry\" : \"\",\n" + "      \"ancestry_description\" : \"\",\n" + "      \"countryRecruitement\" : \"Germany\",\n" + "      \"stage\" : \"Replication\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d515077dcf21d0001eee22b\"\n" + "        }\n" + "      }\n" + "    } ]\n" + "  },\n" + "  \"_links\" : {\n" + "    \"self\" : {\n" + "      \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d515077dcf21d0001eee22b/samples\"\n" + "    }\n" + "  },\n" + "  \"page\" : {\n" + "    \"size\" : 20,\n" + "    \"totalElements\" : 7,\n" + "    \"totalPages\" : 1,\n" + "    \"number\" : 0\n" + "  }\n" + "}";
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        objectMapper.registerModule(new JodaModule());
        DepositionSampleListWrapper samples = objectMapper.readValue(json, DepositionSampleListWrapper.class);
        assertNotNull(samples);
    // assertNotNull(publication.getPublications().get(0).getPublicationDate().year());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) IOException(java.io.IOException) DepositionSampleListWrapper(uk.ac.ebi.spot.goci.model.deposition.util.DepositionSampleListWrapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 12 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project goci by EBISPOT.

the class DepositionSubmissionTest method testReadBodyOfWorkSubmission.

@Test
public void testReadBodyOfWorkSubmission() {
    try {
        Resource resource = new ClassPathResource("bom-submission.json");
        assertTrue(resource.exists());
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JodaModule());
        DepositionSubmission submission = objectMapper.readValue(resource.getFile(), DepositionSubmission.class);
        assertNotNull(submission);
        assertTrue(submission.getCreated().getTimestamp().toString().equals("2020-06-09T11:44:33.972Z"));
        assertNotNull(submission.getStatus());
        assertNotNull(submission.getBodyOfWork());
        assertEquals(submission.getBodyOfWork().getTitle(), "Test piece of work");
        assertNull(submission.getPublication());
        assertNotNull(submission.getStudies().get(0).getSummaryStatisticsFile());
        assertEquals(submission.getStudies().get(0).getSummaryStatisticsFile(), "abc123.tsv");
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 13 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project goci by EBISPOT.

the class DepositionSubmissionTest method testReadSubmissions.

@Test
public void testReadSubmissions() {
    try {
        Resource resource = new ClassPathResource("submissions.json");
        assertTrue(resource.exists());
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JodaModule());
        DepositionSubmissionListWrapper submissionList = objectMapper.readValue(resource.getFile(), DepositionSubmissionListWrapper.class);
        assertNotNull(submissionList);
        assertTrue(submissionList.getWrapper().getSubmissions().get(0).getCreated().getTimestamp().toString().equals("2019-08-12T11:33:45.005Z"));
        assertNotNull(submissionList.getWrapper().getSubmissions().get(0).getStatus());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) DepositionSubmissionListWrapper(uk.ac.ebi.spot.goci.model.deposition.util.DepositionSubmissionListWrapper) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 14 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project beam by apache.

the class MetricsHttpSink method serializeMetrics.

private String serializeMetrics(MetricQueryResults metricQueryResults) throws Exception {
    SimpleModule module = new JodaModule();
    module.addSerializer(new MetricNameSerializer(MetricName.class));
    module.addSerializer(new MetricKeySerializer(MetricKey.class));
    module.addSerializer(new MetricResultSerializer(MetricResult.class));
    objectMapper.registerModule(module);
    objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
    // need to register a filter as soon as @JsonFilter annotation is specified.
    // So specify an pass through filter
    SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.serializeAll();
    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider.addFilter("committedMetrics", filter);
    objectMapper.setFilterProvider(filterProvider);
    String result;
    try {
        result = objectMapper.writeValueAsString(metricQueryResults);
    } catch (JsonMappingException exception) {
        if ((exception.getCause() instanceof UnsupportedOperationException) && exception.getCause().getMessage().contains("committed metrics")) {
            filterProvider.removeFilter("committedMetrics");
            filter = SimpleBeanPropertyFilter.serializeAllExcept("committed");
            filterProvider.addFilter("committedMetrics", filter);
            result = objectMapper.writeValueAsString(metricQueryResults);
        } else {
            throw exception;
        }
    }
    return result;
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) MetricResult(org.apache.beam.sdk.metrics.MetricResult) MetricName(org.apache.beam.sdk.metrics.MetricName) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) MetricKey(org.apache.beam.sdk.metrics.MetricKey) SimpleBeanPropertyFilter(com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 15 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project graylog2-server by Graylog2.

the class InMemorySearchJobServiceTest method setup.

@Test
public void setup() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final TypeFactory typeFactory = mapper.getTypeFactory().withClassLoader(this.getClass().getClassLoader());
    this.objectMapper = mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE).setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy()).setTypeFactory(typeFactory).registerModule(new GuavaModule()).registerModule(new JodaModule()).registerModule(new Jdk8Module()).registerModule(new JavaTimeModule()).registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false)).registerModule(new SimpleModule("Graylog").addKeyDeserializer(Period.class, new JodaTimePeriodKeyDeserializer()).addSerializer(new RangeJsonSerializer()).addSerializer(new SizeSerializer()).addSerializer(new ObjectIdSerializer()));
    // kludge because we don't have an injector in tests
    ImmutableMap<String, Class> subtypes = ImmutableMap.<String, Class>builder().put(StreamFilter.NAME, StreamFilter.class).put(ElasticsearchQueryString.NAME, ElasticsearchQueryString.class).put(MessageList.NAME, MessageList.class).build();
    subtypes.forEach((name, klass) -> objectMapper.registerSubtypes(new NamedType(klass, name)));
}
Also used : SizeSerializer(org.graylog2.shared.jackson.SizeSerializer) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Period(org.joda.time.Period) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) JodaTimePeriodKeyDeserializer(org.graylog2.jackson.JodaTimePeriodKeyDeserializer) MetricsModule(com.codahale.metrics.json.MetricsModule) PropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategy) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) ObjectIdSerializer(org.graylog2.database.ObjectIdSerializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) RangeJsonSerializer(org.graylog2.shared.rest.RangeJsonSerializer) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.Test)

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