Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.chm.converter.protostuff.codec.factory;
import com.chm.converter.core.lang.Pair;
import com.chm.converter.core.reflect.ConverterTypes;
import com.chm.converter.core.reflect.TypeToken;
import com.chm.converter.core.universal.UniversalFactory;
import com.chm.converter.core.universal.UniversalGenerate;
import com.chm.converter.protostuff.codec.ProtostuffCodec;
import com.chm.converter.protostuff.codec.RuntimeTypeCodec;
import io.protostuff.Input;
import io.protostuff.Output;
import io.protostuff.ProtostuffException;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;
/**
* map类型编解码
*
* @author caihongming
* @version v1.0
* @date 2021-11-18
**/
public class MapCodecFactory implements UniversalFactory {
/**
* The field name of the Map.Entry.
*/
public static final String FIELD_NAME_ENTRY = "e";
/**
* The field name of the key.
*/
public static final String FIELD_NAME_KEY = "k";
/**
* The field name of the value;
*/
public static final String FIELD_NAME_VALUE = "v";
@Override
public ProtostuffCodec create(UniversalGenerate generate, TypeToken> typeToken) {
Class> rawTypeOfSrc = typeToken.getRawType();
if (!Map.class.isAssignableFrom(rawTypeOfSrc)) {
return null;
}
Type type = typeToken.getType();
Type[] keyAndValueTypes = ConverterTypes.getMapKeyAndValueTypes(type, rawTypeOfSrc);
ProtostuffCodec kCodec = new RuntimeTypeCodec(generate, generate.get(keyAndValueTypes[0]),
keyAndValueTypes[0]);
ProtostuffCodec vCodec = new RuntimeTypeCodec(generate, generate.get(keyAndValueTypes[1]),
keyAndValueTypes[1]);
return new MapCodec(typeToken, kCodec, vCodec);
}
public static class MapCodec extends ProtostuffCodec