@Test public void extensionTypeCustomDeserializers() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); MessagePacker packer = MessagePack.newDefaultPacker(out); packer.packArrayHeader(5); packer.packInt(42); packer.packString("foo bar"); { TinyPojo t0 = new TinyPojo(); t0.t = "t0"; TinyPojo t1 = new TinyPojo(); t1.t = "t1"; NestedListComplexPojo parent = new NestedListComplexPojo(); parent.s = "parent"; parent.foos = Arrays.asList(t0, t1); byte[] bytes = objectMapper.writeValueAsBytes(parent); packer.packExtensionTypeHeader((byte) 17, bytes.length); packer.addPayload(bytes); } { Map<String, Integer> map = new HashMap<String, Integer>(); map.put("one", 1); map.put("two", 2); byte[] bytes = objectMapper.writeValueAsBytes(map); packer.packExtensionTypeHeader((byte) 99, bytes.length); packer.addPayload(bytes); } { packer.packExtensionTypeHeader((byte) 31, 4); packer.addPayload(new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE}); } packer.close(); ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers(); extTypeCustomDesers.addTargetClass((byte) 17, NestedListComplexPojo.class); extTypeCustomDesers.addTargetTypeReference((byte) 99, new TypeReference<Map<String, Integer>>() {}); extTypeCustomDesers.addCustomDeser((byte) 31, new ExtensionTypeCustomDeserializers.Deser() { @Override public Object deserialize(byte[] data) throws IOException { if (Arrays.equals(data, new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE})) { return "Java"; } return "Not Java"; } } ); ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory().setExtTypeCustomDesers(extTypeCustomDesers)); List<Object> values = objectMapper.readValue(new ByteArrayInputStream(out.toByteArray()), new TypeReference<List<Object>>() {}); assertThat(values.size(), is(5)); assertThat((Integer) values.get(0), is(42)); assertThat((String) values.get(1), is("foo bar")); { Object v = values.get(2); assertThat(v, is(instanceOf(NestedListComplexPojo.class))); NestedListComplexPojo pojo = (NestedListComplexPojo) v; assertThat(pojo.s, is("parent")); assertThat(pojo.foos.size(), is(2)); assertThat(pojo.foos.get(0).t, is("t0")); assertThat(pojo.foos.get(1).t, is("t1")); } { Object v = values.get(3); assertThat(v, is(instanceOf(Map.class))); Map<String, Integer> map = (Map<String, Integer>) v; assertThat(map.size(), is(2)); assertThat(map.get("one"), is(1)); assertThat(map.get("two"), is(2)); } assertThat((String) values.get(4), is("Java")); }
@Override public void close() throws IOException { try { if (isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)) { MessageUnpacker messageUnpacker = getMessageUnpacker(); messageUnpacker.close(); } } finally { isClosed = true; } }
MessagePackParser extends ParserMinimalBase { @Override public void close() throws IOException { try { if (isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)) { MessageUnpacker messageUnpacker = getMessageUnpacker(); messageUnpacker.close(); } } finally { isClosed = true; } } }
MessagePackParser extends ParserMinimalBase { @Override public void close() throws IOException { try { if (isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)) { MessageUnpacker messageUnpacker = getMessageUnpacker(); messageUnpacker.close(); } } finally { isClosed = true; } } MessagePackParser(IOContext ctxt, int features, ObjectCodec objectCodec, InputStream in);  MessagePackParser(
            IOContext ctxt,
            int features,
            ObjectCodec objectCodec,
            InputStream in,
            boolean reuseResourceInParser);  MessagePackParser(IOContext ctxt, int features, ObjectCodec objectCodec, byte[] bytes);  MessagePackParser(
            IOContext ctxt,
            int features,
            ObjectCodec objectCodec,
            byte[] bytes,
            boolean reuseResourceInParser); private  MessagePackParser(IOContext ctxt,
            int features,
            MessageBufferInput input,
            ObjectCodec objectCodec,
            Object src,
            boolean reuseResourceInParser); }
MessagePackParser extends ParserMinimalBase { @Override public void close() throws IOException { try { if (isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)) { MessageUnpacker messageUnpacker = getMessageUnpacker(); messageUnpacker.close(); } } finally { isClosed = true; } } MessagePackParser(IOContext ctxt, int features, ObjectCodec objectCodec, InputStream in);  MessagePackParser(
            IOContext ctxt,
            int features,
            ObjectCodec objectCodec,
            InputStream in,
            boolean reuseResourceInParser);  MessagePackParser(IOContext ctxt, int features, ObjectCodec objectCodec, byte[] bytes);  MessagePackParser(
            IOContext ctxt,
            int features,
            ObjectCodec objectCodec,
            byte[] bytes,
            boolean reuseResourceInParser); private  MessagePackParser(IOContext ctxt,
            int features,
            MessageBufferInput input,
            ObjectCodec objectCodec,
            Object src,
            boolean reuseResourceInParser); void setExtensionTypeCustomDeserializers(ExtensionTypeCustomDeserializers extTypeCustomDesers); @Override ObjectCodec getCodec(); @Override void setCodec(ObjectCodec c); @Override Version version(); @Override JsonToken nextToken(); @Override String getText(); @Override char[] getTextCharacters(); @Override boolean hasTextCharacters(); @Override int getTextLength(); @Override int getTextOffset(); @Override byte[] getBinaryValue(Base64Variant b64variant); @Override Number getNumberValue(); @Override int getIntValue(); @Override long getLongValue(); @Override BigInteger getBigIntegerValue(); @Override float getFloatValue(); @Override double getDoubleValue(); @Override BigDecimal getDecimalValue(); @Override Object getEmbeddedObject(); @Override NumberType getNumberType(); @Override void close(); @Override boolean isClosed(); @Override JsonStreamContext getParsingContext(); @Override JsonLocation getTokenLocation(); @Override JsonLocation getCurrentLocation(); @Override void overrideCurrentName(String name); @Override String getCurrentName(); }
MessagePackParser extends ParserMinimalBase { @Override public void close() throws IOException { try { if (isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)) { MessageUnpacker messageUnpacker = getMessageUnpacker(); messageUnpacker.close(); } } finally { isClosed = true; } } MessagePackParser(IOContext ctxt, int features, ObjectCodec objectCodec, InputStream in);  MessagePackParser(
            IOContext ctxt,
            int features,
            ObjectCodec objectCodec,
            InputStream in,
            boolean reuseResourceInParser);  MessagePackParser(IOContext ctxt, int features, ObjectCodec objectCodec, byte[] bytes);  MessagePackParser(
            IOContext ctxt,
            int features,
            ObjectCodec objectCodec,
            byte[] bytes,
            boolean reuseResourceInParser); private  MessagePackParser(IOContext ctxt,
            int features,
            MessageBufferInput input,
            ObjectCodec objectCodec,
            Object src,
            boolean reuseResourceInParser); void setExtensionTypeCustomDeserializers(ExtensionTypeCustomDeserializers extTypeCustomDesers); @Override ObjectCodec getCodec(); @Override void setCodec(ObjectCodec c); @Override Version version(); @Override JsonToken nextToken(); @Override String getText(); @Override char[] getTextCharacters(); @Override boolean hasTextCharacters(); @Override int getTextLength(); @Override int getTextOffset(); @Override byte[] getBinaryValue(Base64Variant b64variant); @Override Number getNumberValue(); @Override int getIntValue(); @Override long getLongValue(); @Override BigInteger getBigIntegerValue(); @Override float getFloatValue(); @Override double getDoubleValue(); @Override BigDecimal getDecimalValue(); @Override Object getEmbeddedObject(); @Override NumberType getNumberType(); @Override void close(); @Override boolean isClosed(); @Override JsonStreamContext getParsingContext(); @Override JsonLocation getTokenLocation(); @Override JsonLocation getCurrentLocation(); @Override void overrideCurrentName(String name); @Override String getCurrentName();  }