Skip to content

Commit 8559c14

Browse files
committed
Use original codec to support v0.6 format when serializing complex type
1 parent d9217a9 commit 8559c14

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackGenerator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import com.fasterxml.jackson.core.base.GeneratorBase;
2323
import com.fasterxml.jackson.core.io.SerializedString;
2424
import com.fasterxml.jackson.core.json.JsonWriteContext;
25-
import com.fasterxml.jackson.databind.ObjectMapper;
2625
import org.msgpack.core.MessagePack;
2726
import org.msgpack.core.MessagePacker;
2827
import org.msgpack.core.buffer.OutputStreamBufferOutput;
2928

29+
import java.io.ByteArrayOutputStream;
3030
import java.io.IOException;
3131
import java.io.OutputStream;
3232
import java.math.BigDecimal;
@@ -243,10 +243,10 @@ else if (v instanceof MessagePackExtensionType) {
243243
}
244244
else {
245245
messagePacker.flush();
246-
MessagePackFactory messagePackFactory = new MessagePackFactory(packerConfig);
247-
messagePackFactory.setReuseResourceInGenerator(false);
248-
ObjectMapper objectMapper = new ObjectMapper(messagePackFactory);
249-
output.write(objectMapper.writeValueAsBytes(v));
246+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
247+
MessagePackGenerator messagePackGenerator = new MessagePackGenerator(getFeatureMask(), getCodec(), outputStream, packerConfig, false);
248+
getCodec().writeValue(messagePackGenerator, v);
249+
output.write(outputStream.toByteArray());
250250
}
251251
}
252252

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackGeneratorTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,4 +711,25 @@ public void testComplexTypeKey()
711711
assertThat(unpacker.unpackString(), is("foo"));
712712
assertThat(unpacker.unpackInt(), is(42));
713713
}
714+
715+
@Test
716+
public void testComplexTypeKeyWithV06Format()
717+
throws IOException
718+
{
719+
HashMap<TinyPojo, Integer> map = new HashMap<TinyPojo, Integer>();
720+
TinyPojo pojo = new TinyPojo();
721+
pojo.t = "foo";
722+
map.put(pojo, 42);
723+
724+
ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
725+
objectMapper.setAnnotationIntrospector(new JsonArrayFormat());
726+
objectMapper.setSerializerFactory(new MessagePackSerializerFactory());
727+
byte[] bytes = objectMapper.writeValueAsBytes(map);
728+
729+
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(bytes);
730+
assertThat(unpacker.unpackMapHeader(), is(1));
731+
assertThat(unpacker.unpackArrayHeader(), is(1));
732+
assertThat(unpacker.unpackString(), is("foo"));
733+
assertThat(unpacker.unpackInt(), is(42));
734+
}
714735
}

0 commit comments

Comments
 (0)