Skip to content

Instantly share code, notes, and snippets.

@skizzybiz
Last active August 29, 2015 14:17
Show Gist options
  • Save skizzybiz/7fe2537641bb157b868a to your computer and use it in GitHub Desktop.
Save skizzybiz/7fe2537641bb157b868a to your computer and use it in GitHub Desktop.
option java_package="test.protobuf";
message Foo {
optional int32 foo = 1;
}
import com.fasterxml.jackson.annotation.JsonCreator;
import test.protobuf.Test;
public class Wrapper {
public Test.Foo foo;
@JsonCreator
public Wrapper(Test.Foo foo) {
this.foo = foo;
}
public Wrapper() {
this(null);
}
@Override
public boolean equals(Object other) {
if (this == other) return true;
if ( !(other instanceof Wrapper)) return false;
final Wrapper wrapper = (Wrapper) other;
if (foo == null) return wrapper.foo == null;
return wrapper.foo.equals(foo);
}
}
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hubspot.jackson.datatype.protobuf.ProtobufModule;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class WrapperTest {
@Test
public void wrapperFromJson() throws Exception {
ObjectMapper mapper = new ObjectMapper().registerModule(new ProtobufModule());
assertEquals(new Wrapper(), mapper.readValue(this.getClass().getResource("wrapper.json"), Wrapper.class));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment