-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8321c68
commit c6c1f97
Showing
4 changed files
with
175 additions
and
13 deletions.
There are no files selected for viewing
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
122 changes: 122 additions & 0 deletions
122
...f/src/test/java/com/fasterxml/jackson/dataformat/protobuf/RoundtripNestedMessageTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package com.fasterxml.jackson.dataformat.protobuf; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper; | ||
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema; | ||
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader; | ||
|
||
public class RoundtripNestedMessageTest extends ProtobufTestBase | ||
{ | ||
private static final String VALUE_A = "value"; | ||
private static final String VALUE_B = "value-b"; | ||
private static final String VALUE_C = "valc"; | ||
private static final String VALUE_SUB_A = "a-value!"; | ||
|
||
private static final String PROTO = // | ||
"message TestObject {\n" + // | ||
"optional string a = 1;\n" + // | ||
"optional TestSub b = 2;\n" + // | ||
"}\n" + // | ||
"message TestSub {;\n" + // | ||
"optional string c = 2;\n" + // | ||
"optional string b = 3;\n" + // | ||
"optional TestSubSub d = 4;\n" + // | ||
"}\n" + // | ||
"message TestSubSub {;\n" + // | ||
"optional string a = 1;\n" + // | ||
"}\n"; // | ||
|
||
static class TestObject { | ||
String a; | ||
TestSub b; | ||
|
||
public String getA() { | ||
return a; | ||
} | ||
|
||
public void setA(String a) { | ||
this.a = a; | ||
} | ||
|
||
public TestSub getB() { | ||
return b; | ||
} | ||
|
||
public void setB(TestSub b) { | ||
this.b = b; | ||
} | ||
} | ||
|
||
// ordering would be needed prior to fix for [#59] | ||
//@com.fasterxml.jackson.annotation.JsonPropertyOrder({"d", "b", "c"}) | ||
static class TestSub { | ||
String b; | ||
String c; | ||
TestSubSub d; | ||
|
||
public String getB() { | ||
return b; | ||
} | ||
|
||
public void setB(String b) { | ||
this.b = b; | ||
} | ||
|
||
public String getC() { | ||
return c; | ||
} | ||
|
||
public void setC(String c) { | ||
this.c = c; | ||
} | ||
|
||
public TestSubSub getD() { | ||
return d; | ||
} | ||
|
||
public void setD(TestSubSub d) { | ||
this.d = d; | ||
} | ||
} | ||
|
||
public static class TestSubSub { | ||
String a; | ||
|
||
public String getA() { | ||
return a; | ||
} | ||
|
||
public void setA(String a) { | ||
this.a = a; | ||
} | ||
} | ||
|
||
@Test | ||
public void testNestedRoundtrip() throws IOException | ||
{ | ||
TestObject testClass = new TestObject(); | ||
ProtobufMapper om = new ProtobufMapper(); | ||
ProtobufSchema s = ProtobufSchemaLoader.std.parse(PROTO); | ||
testClass.a = VALUE_A; | ||
testClass.b = new TestSub(); | ||
testClass.b.b = VALUE_B; | ||
testClass.b.c = VALUE_C; | ||
// if this following row is commented out, test succeeds with old code | ||
testClass.b.d = new TestSubSub(); | ||
testClass.b.d.a = VALUE_SUB_A; | ||
|
||
byte[] proto = om.writer(s) | ||
.writeValueAsBytes(testClass); | ||
TestObject res = om.readerFor(TestObject.class).with(s) | ||
.readValue(proto); | ||
|
||
Assert.assertEquals(VALUE_A, res.a); | ||
Assert.assertEquals(VALUE_C, res.b.c); | ||
Assert.assertEquals(VALUE_B, res.b.b); | ||
Assert.assertEquals(VALUE_SUB_A, res.b.d.a); | ||
} | ||
} |
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