AutoJackson

Additional

Language
Java
Version
N/A
Created
Aug 19, 2015
Updated
Apr 8, 2018
Owner
Artem Zinnatullin :slowpoke: (artem-zinnatullin)
Contributors
Artem Zinnatullin :slowpoke: (artem-zinnatullin)
bryant1410
hgschmie
HuaTang92
4
Activity
Badge
Generate
Download
Source code

Announcement

AutoJackson

Why AutoValue is awesome?

Just read Google's explanation!

TLTR: It gives you immutability (thread safety!), equals(), hashCode() and toString() for free!


Serialization and deserialization:

@Test
public void shouldSerializeToJson() throws JsonProcessingException {
  ObjectMapper objectMapper = new ObjectMapper();

  Tweet tweet = Tweet.builder()
    .author("@artem_zin")
    .content("Immutability for everybody!")
    .build();

  assertThatJson(objectMapper.writeValueAsString(tweet))
    .isEqualTo("{\"author\":\"@artem_zin\",\"content\":\"Immutability for everybody!\"}");
}

@Test
public void shouldDeserializeFromJson() throws IOException {
  ObjectMapper objectMapper = new ObjectMapper();

  String json = "{\"author\":\"@artem_zin\",\"content\":\"Immutability for everybody!\"}";

  Tweet tweet = objectMapper.readValue(json, Tweet.class);

  assertThat(tweet.author()).isEqualTo("@artem_zin");
  assertThat(tweet.content()).isEqualTo("Immutability for everybody!");
}

Build the project

Run sh ci.sh.

Contact me

https://twitter.com/artem_zin