com.chm.converter.protostuff.codec.factory.ObjectCodecFactory Maven / Gradle / Ivy
package com.chm.converter.protostuff.codec.factory;
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 java.io.IOException;
import java.lang.reflect.TypeVariable;
/**
* @author caihongming
* @version v1.0
* @date 2022-02-18
**/
public class ObjectCodecFactory implements UniversalFactory {
public static final String FIELD_NAME_VALUE = "o";
@Override
public ProtostuffCodec create(UniversalGenerate generate, TypeToken> typeToken) {
if (typeToken.getRawType() == Object.class &&
typeToken.getType() instanceof TypeVariable) {
return new RuntimeTypeCodec<>(generate, new ObjectCodec(generate), typeToken.getType());
} else if (typeToken.getRawType() == Object.class) {
return new ObjectCodec(generate);
}
return null;
}
public static class ObjectCodec extends ProtostuffCodec