|
15 | 15 | // |
16 | 16 | package org.msgpack.jackson.dataformat; |
17 | 17 |
|
| 18 | +import com.fasterxml.jackson.annotation.JsonProperty; |
18 | 19 | import com.fasterxml.jackson.core.JsonGenerator; |
19 | 20 | import com.fasterxml.jackson.core.JsonEncoding; |
20 | 21 | import com.fasterxml.jackson.core.JsonProcessingException; |
@@ -884,4 +885,54 @@ public void serializeStringAsBigInteger() |
884 | 885 | MessagePack.newDefaultUnpacker(objectMapper.writeValueAsBytes(bi)).unpackDouble(), |
885 | 886 | is(bi.doubleValue())); |
886 | 887 | } |
| 888 | + |
| 889 | + @Test |
| 890 | + public void testNestedSerialization() throws Exception |
| 891 | + { |
| 892 | + // The purpose of this test is to confirm if MessagePackFactory.setReuseResourceInGenerator(false) |
| 893 | + // works as a workaround for https://github.com/msgpack/msgpack-java/issues/508 |
| 894 | + ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory().setReuseResourceInGenerator(false)); |
| 895 | + OuterClass outerClass = objectMapper.readValue( |
| 896 | + objectMapper.writeValueAsBytes(new OuterClass("Foo")), |
| 897 | + OuterClass.class); |
| 898 | + assertEquals("Foo", outerClass.getName()); |
| 899 | + } |
| 900 | + |
| 901 | + static class OuterClass |
| 902 | + { |
| 903 | + private final String name; |
| 904 | + |
| 905 | + public OuterClass(@JsonProperty("name") String name) |
| 906 | + { |
| 907 | + this.name = name; |
| 908 | + } |
| 909 | + |
| 910 | + public String getName() |
| 911 | + throws IOException |
| 912 | + { |
| 913 | + // Serialize nested class object |
| 914 | + ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); |
| 915 | + InnerClass innerClass = objectMapper.readValue( |
| 916 | + objectMapper.writeValueAsBytes(new InnerClass("Bar")), |
| 917 | + InnerClass.class); |
| 918 | + assertEquals("Bar", innerClass.getName()); |
| 919 | + |
| 920 | + return name; |
| 921 | + } |
| 922 | + } |
| 923 | + |
| 924 | + static class InnerClass |
| 925 | + { |
| 926 | + private final String name; |
| 927 | + |
| 928 | + public InnerClass(@JsonProperty("name") String name) |
| 929 | + { |
| 930 | + this.name = name; |
| 931 | + } |
| 932 | + |
| 933 | + public String getName() |
| 934 | + { |
| 935 | + return name; |
| 936 | + } |
| 937 | + } |
887 | 938 | } |
0 commit comments