All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.norberg.automatter.example.ComplexGenericJacksonExample Maven / Gradle / Ivy

There is a newer version: 0.26.2
Show newest version
package io.norberg.automatter.example;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.List;

import io.norberg.automatter.jackson.AutoMatterModule;

import static java.lang.System.out;
import static java.util.Arrays.asList;

public class ComplexGenericJacksonExample {

  public static void main(final String... args) throws IOException {
    // Register the AutoMatterModule to handle deserialization
    ObjectMapper mapper = new ObjectMapper()
        .registerModule(new AutoMatterModule());

    ComplexGenericFoobar, ComparableList> foobar =
        new ComplexGenericFoobarBuilder, ComparableList>()
            .foo("foo")
            .bar(17)
            .baz(asList(13, 4711))
            .quux(ComparableList.of(1, 2, 3))
            .name("generics")
            .build();

    String json = mapper.writeValueAsString(foobar);
    out.println("json: " + json);

    ComplexGenericFoobar, ComparableList> parsed = mapper.readValue(
        json, new TypeReference, ComparableList>>() {});

    out.println("parsed: " + parsed);

    out.println("equals: " + foobar.equals(parsed));
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy