Last active
August 29, 2015 14:17
-
-
Save skizzybiz/7fe2537641bb157b868a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
option java_package="test.protobuf"; | |
message Foo { | |
optional int32 foo = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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