Skip to content

Instantly share code, notes, and snippets.

@pcarrier
Last active June 3, 2021 20:01
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save pcarrier/14d3a8e249d804cfbdee to your computer and use it in GitHub Desktop.
Save pcarrier/14d3a8e249d804cfbdee to your computer and use it in GitHub Desktop.
package com.twitter.autobake.misc;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import lombok.Builder;
import lombok.Data;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
public class LombokJacksonTest {
@Test
public void testJsonBuilders() throws IOException {
final ObjectMapper mapper = new ObjectMapper();
final JsonTest hello = new JsonTest(10, "hello");
final byte[] bytes = mapper.writeValueAsBytes(hello);
final JsonTest read = mapper.readValue(bytes, JsonTest.class);
assertEquals(10, read.getInteger());
assertEquals("hello", read.getString());
}
@JsonDeserialize(builder = JsonTest.JsonTestBuilder.class)
@Builder
@Data
public static final class JsonTest {
private final int integer;
private final String string;
@JsonPOJOBuilder(withPrefix = "")
public static final class JsonTestBuilder {
}
}
}
@ayushmaanbhav
Copy link

Thanks a ton ! 👍
I was stuck into this lombok + jackson for a long time....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment