@@ -0,0 +1,2564 @@
+package com.instagram.common.json.annotation.processor.parent;%0A%0Aimport com.fasterxml.jackson.core.JsonGenerator;%0Aimport com.fasterxml.jackson.core.JsonParser;%0Aimport com.fasterxml.jackson.core.JsonToken;%0A%0Aimport java.io.IOException;%0Aimport java.util.HashMap;%0A%0Aimport javax.annotation.Nullable;%0A%0Apublic class DynamicDispatchAdapter%3CT extends DynamicDispatchAdapter.TypeNameProvider%3E %7B%0A    public interface TypeNameProvider %7B%0A        public String getTypeName();%0A    %7D%0A%0A    public interface TypeAdapter%3CT%3E %7B%0A        void serializeToJson(JsonGenerator generator, T object) throws IOException;%0A        T parseFromJson(JsonParser parser) throws IOException;%0A    %7D%0A%0A    private HashMap%3CString,TypeAdapter%3CT%3E%3E mAdapterMap = new HashMap%3C%3E();%0A%0A    public void register(String typeName, TypeAdapter%3CT%3E adapter) %7B%0A        if (mAdapterMap.containsKey(typeName)) %7B%0A            String message = String.format(%0A                    %22Duplicate handler name. %25s is already mapped to an instance of %25s%22,%0A                    typeName,%0A                    mAdapterMap.get(typeName));%0A            throw new IllegalArgumentException(message);%0A        %7D%0A        mAdapterMap.put(typeName, adapter);%0A    %7D%0A%0A    public void unregister(String typeName) %7B%0A        mAdapterMap.remove(typeName);%0A    %7D%0A%0A    public T parseFromJson(JsonParser parser) throws IOException %7B%0A        if (parser.getCurrentToken() != JsonToken.START_ARRAY) %7B%0A            parser.skipChildren();%0A            return null;%0A        %7D%0A%0A        parser.nextToken();%0A        if (parser.getCurrentToken() != JsonToken.VALUE_STRING) %7B%0A            parser.skipChildren();%0A            return null;%0A        %7D%0A%0A        String typeName = parser.getText();%0A        parser.nextToken();%0A        final T instance = getAdapter(typeName).parseFromJson(parser);%0A        parser.nextToken();%0A        return instance;%0A    %7D%0A%0A    private TypeAdapter%3CT%3E getAdapter(String typeName) %7B%0A        final @Nullable TypeAdapter%3CT%3E adapter = mAdapterMap.get(typeName);%0A        if (adapter == null) %7B%0A            final String message = String.format(%0A                    %22No TypeAdapter registered for type name: %25s%22,%0A                    typeName);%0A            throw new IllegalArgumentException(message);%0A        %7D%0A%0A        return adapter;%0A    %7D%0A%0A    public void serialize(JsonGenerator generator, String fieldName, T object) throws IOException %7B%0A        generator.writeStartArray();%0A        generator.writeString(object.getTypeName());%0A        getAdapter(object.getTypeName()).serializeToJson(generator, object);%0A        generator.writeEndArray();%0A    %7D%0A%7D%0A

Implement TypeAdapter based dispatcher