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());
}
}
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());
}
}
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());
}
}
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;
}
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)));
}
Aggregations