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

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

package io.norberg.automatter.example;

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

import java.io.IOException;

import io.norberg.automatter.jackson.AutoMatterModule;

import static java.lang.System.out;

public class SimpleGenericJacksonExample {

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

    GenericFoobar foobar = new GenericFoobarBuilder()
        .foo(17)
        .bar(1, 2, 3)
        .putBaz("hello world", 4711)
        .build();

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

    GenericFoobar parsed = mapper.readValue(json, new TypeReference>() {});
    out.println("parsed: " + parsed);

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy