Example usage for com.fasterxml.jackson.datatype.jdk8 Jdk8Module Jdk8Module

List of usage examples for com.fasterxml.jackson.datatype.jdk8 Jdk8Module Jdk8Module

Introduction

In this page you can find the example usage for com.fasterxml.jackson.datatype.jdk8 Jdk8Module Jdk8Module.

Prototype

Jdk8Module

Source Link

Usage

From source file:it.polimi.diceH2020.SPACE4Cloud.shared.Test2.java

@Test
public void test3() {
    System.out.println("-------------");
    InstanceDataMultiProvider sol = InstanceDataMultiProviderGenerator.build();
    try {/*from  w  w w.  j  a  v a  2 s  . c  o  m*/
        ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module());

        String serialized = mapper.writeValueAsString(sol);
        System.out.println(serialized);
        InstanceDataMultiProvider data2 = mapper.readValue(serialized, InstanceDataMultiProvider.class);
        System.out.println(data2.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.orange.ngsi2.model.RegistrationTest.java

@Test
public void deserializationEntityTypeTest() throws IOException {

    ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jdk8Module());
    Registration registration = objectMapper.readValue(jsonString, Registration.class);
    assertEquals("abcdefg", registration.getId());
    assertEquals(new URL("http://weather.example.com/ngsi"), registration.getCallback());
    assertEquals("PT1M", registration.getDuration());
    assertEquals(1, registration.getSubject().getEntities().size());
    assertEquals("Bcn_Welt", registration.getSubject().getEntities().get(0).getId().get());
    assertEquals("Room", registration.getSubject().getEntities().get(0).getType().get());
    assertEquals(1, registration.getSubject().getAttributes().size());
    assertEquals("temperature", registration.getSubject().getAttributes().get(0));
    assertEquals(2, registration.getMetadata().size());
    assertTrue(registration.getMetadata().containsKey("providingService"));
    assertTrue(registration.getMetadata().containsKey("providingAuthority"));
}

From source file:io.github.retz.web.feign.Retz.java

static Retz connect(URI uri, Authenticator authenticator, SSLSocketFactory socketFactory,
        HostnameVerifier hostnameVerifier) {
    String url = Objects.requireNonNull(uri, "uri cannot be null").toString();
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new Jdk8Module());
    return Feign.builder().client(new Client.Default(socketFactory, hostnameVerifier)).logger(new Slf4jLogger())
            .encoder(new JacksonEncoder(mapper)).decoder(new JacksonDecoder(mapper))
            .errorDecoder(new ErrorResponseDecoder(mapper))
            .requestInterceptor(new AuthHeaderInterceptor(authenticator)).target(Retz.class, url);
}

From source file:org.jooby.jackson.Json.java

public Json(final ObjectMapper mapper) {
    this.mapper = checkNotNull(mapper, "An object mapper is required.");
    this.modules.add(new Jdk8Module());
    // Java 8 dates
    this.modules.add(new JSR310Module());
}

From source file:ubicrypt.core.Utils.java

public static void configureMapper(final ObjectMapper mapper) {
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new SimpleModule("ubicrypt module") {
        {/*www.j  av a2s  .c  om*/
            addSerializer(new PGPKValueSerializer(PGPKValue.class));
            addDeserializer(PGPKValue.class, new PGPKValueDeserializer(PGPKValue.class));
            addSerializer(new PathSerializer(Path.class));
            addDeserializer(Path.class, new PathDeserializer(Path.class));
        }
    });
    mapper.registerModule(new AfterburnerModule());
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}

From source file:no.ssb.jsonstat.v2.deser.DatasetDeserializerTest.java

@Test
public void testDimensionOrder() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new JsonStatModule());

    URL resource = getResource(getClass(), "dimOrder.json");

    JsonParser jsonParser = mapper.getFactory().createParser(resource.openStream());
    jsonParser.nextValue();//from w w w. ja v a  2  s . c  o m

    DatasetBuildable deserialize = ds.deserialize(jsonParser, mapper.getDeserializationContext());

    assertThat(deserialize.build().getDimension().keySet()).containsExactly("A", "B", "C");

}

From source file:org.ng200.openolympus.factory.JacksonSerializationFactory.java

/**
 * @return Jackson ObjectMapper that has the necessary configuration to
 *         serialise and deserialise Cerberus classes
 *//* w w w  .j av  a 2  s .  co m*/
public static ObjectMapper createObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper().enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL)
            .registerModule(new PathSerializationModule()).registerModule(new Jdk8Module())
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    try {
        objectMapper.addMixInAnnotations(Path.class, PathMixin.class);
        objectMapper.addMixInAnnotations(Class.forName("sun.nio.fs.UnixPath"), PathMixin.class);
        return objectMapper;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:it.polimi.diceH2020.launcher.model.SimulationsManager.java

public void setInputData(InstanceDataMultiProvider inputData) {
    this.inputData = inputData;

    try {/*from  w  ww  .  j  a  va2  s  .c o m*/
        ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module())
                .enable(SerializationFeature.INDENT_OUTPUT);
        ;
        setInput(Compressor.compress(mapper.writeValueAsString(inputData)));
    } catch (IOException e) {
        setInput("Error");
    }
    setInstanceName(inputData.getId());
    //System.out.println("id:"+inputData.getId());
}

From source file:it.polimi.diceH2020.launcher.LauncherApplication.java

@Bean
public Jdk8Module jdk8Module() {
    return new Jdk8Module();
}