Search in sources :

Example 41 with JodaModule

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

the class DepositionAssociationDtoTest method testReadAssociationResponse.

@Test
public void testReadAssociationResponse() {
    String json = "{\n" + "  \"_embedded\" : {\n" + "    \"associations\" : [ {\n" + "      \"study_tag\" : \"30237584_1\",\n" + "      \"variant_id\" : \"rs11749255\",\n" + "      \"pvalue\" : \"0.0000003\",\n" + "      \"effect_allele\" : \"A\",\n" + "      \"other_allele\" : \"\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d514e99dcf21d0001eee221\"\n" + "        }\n" + "      }\n" + "    }, {\n" + "      \"study_tag\" : \"30237584_2\",\n" + "      \"variant_id\" : \"rs12228810\",\n" + "      \"pvalue\" : \"0.000009\",\n" + "      \"effect_allele\" : \"C\",\n" + "      \"other_allele\" : \"\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d514e99dcf21d0001eee221\"\n" + "        }\n" + "      }\n" + "    }, {\n" + "      \"study_tag\" : \"30237584_2\",\n" + "      \"variant_id\" : \"rs16934621\",\n" + "      \"pvalue\" : \"0.000005\",\n" + "      \"effect_allele\" : \"A\",\n" + "      \"other_allele\" : \"\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d514e99dcf21d0001eee221\"\n" + "        }\n" + "      }\n" + "    }, {\n" + "      \"study_tag\" : \"30237584_2\",\n" + "      \"variant_id\" : \"rs3766160\",\n" + "      \"pvalue\" : \"0.000001\",\n" + "      \"effect_allele\" : \"A\",\n" + "      \"other_allele\" : \"\",\n" + "      \"_links\" : {\n" + "        \"parent\" : {\n" + "          \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d514e99dcf21d0001eee221\"\n" + "        }\n" + "      }\n" + "    } ]\n" + "  },\n" + "  \"_links\" : {\n" + "    \"self\" : {\n" + "      \"href\" : \"http://193.62.54.159/backend/v1/submissions/5d514e99dcf21d0001eee221/associations\"\n" + "    }\n" + "  },\n" + "  \"page\" : {\n" + "    \"size\" : 20,\n" + "    \"totalElements\" : 4,\n" + "    \"totalPages\" : 1,\n" + "    \"number\" : 0\n" + "  }\n" + "}\n";
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        objectMapper.registerModule(new JodaModule());
        DepositionAssociationListWrapper associations = objectMapper.readValue(json, DepositionAssociationListWrapper.class);
        assertNotNull(associations);
        assertNotNull(associations.getAssociations().getAssociations().get(0));
        BigDecimal pValue = new BigDecimal(associations.getAssociations().getAssociations().get(0).getPValue());
        assertNotNull(pValue);
        BigInteger sv = pValue.unscaledValue();
        int exponent = pValue.precision() - pValue.scale() - 1;
        assertEquals(3, sv.intValue());
        assertEquals(-7, exponent);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) BigInteger(java.math.BigInteger) IOException(java.io.IOException) DepositionAssociationListWrapper(uk.ac.ebi.spot.goci.model.deposition.util.DepositionAssociationListWrapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 42 with JodaModule

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

the class Jackson method configure.

private static ObjectMapper configure(ObjectMapper mapper) {
    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new GuavaExtrasModule());
    mapper.registerModule(new CaffeineModule());
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new BlackbirdModule());
    mapper.registerModule(new FuzzyEnumModule());
    mapper.registerModule(new ParameterNamesModule());
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JavaTimeModule());
    mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
    mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());
    mapper.disable(FAIL_ON_UNKNOWN_PROPERTIES);
    return mapper;
}
Also used : BlackbirdModule(com.fasterxml.jackson.module.blackbird.BlackbirdModule) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ParameterNamesModule(com.fasterxml.jackson.module.paramnames.ParameterNamesModule) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule)

Example 43 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project pact-jvm by DiUS.

the class BooksPactProviderTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    target.setControllers(bookController, novelController);
    target.setControllerAdvice(bookControllerAdviceOne, bookControllerAdviceTwo);
    target.setServletPath("/api");
    target.setMessageConvertors(new MappingJackson2HttpMessageConverter(new ObjectMapper().registerModule(new JodaModule()).configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 44 with JodaModule

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

the class TestBillingEventSetJson method setup.

@BeforeClass(groups = "fast")
public void setup() {
    testMapper = new ObjectMapper();
    testMapper.registerModule(new JodaModule());
    testMapper.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeClass(org.testng.annotations.BeforeClass)

Example 45 with JodaModule

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

the class QueryTest method setup.

@Before
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) Before(org.junit.Before)

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