Skip to content

Better Deserialization of Extension Types with Jackson #398

Closed

Description

@fuyumatsuri

If you do a readTree that contains an extension type, the resulting tree will look something like (for example) [1, 2, [MessagePackExtensionType, MessagePackExtensionType']. In order to make this tree usable you need to traverse the whole tree converting any MessagePackExtensionType object to the real object type. It would be much better if reading the tree instead resulted in [1, 2, [RealClass, RealClass]].

Ideally I would like to be able to do something along the lines of

factory = new MessagePackFactory
factory.register(typeId, class, encoder, decoder)

and have MessagePackParser check if a type is registered to return the correct object.

Activity

  1. clarkdo commented on Dec 29, 2016

    @clarkdo

    +1

  2. self-assigned this
    on Jan 3, 2017
  3. komamitsu commented on Jan 19, 2017

    @komamitsu
    Member

    @Chad- @clarkdo Does this feature satisfy your request? https://github.com/msgpack/msgpack-java/pull/408/files#diff-da72e095f423bf63a2b05b8196b564dfR720

        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));
    
  4. komamitsu commented on Jan 25, 2017

    @komamitsu
    Member

    Merged the above feature. I hope it solves this request.

  5. clarkdo commented on Jan 25, 2017

    @clarkdo

    @komamitsu thanks. It should be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions