All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jsoniter.output.ReflectionEncoderFactory Maven / Gradle / Ivy

Go to download

jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go

There is a newer version: 0.9.23
Show newest version
package com.jsoniter.output;

import com.jsoniter.spi.ClassInfo;
import com.jsoniter.spi.Encoder;

import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class ReflectionEncoderFactory {

    public static Encoder.ReflectionEncoder create(ClassInfo classInfo) {
        Class clazz = classInfo.clazz;
        Type[] typeArgs = classInfo.typeArgs;
        if (clazz.isArray()) {
            return new ReflectionArrayEncoder(clazz, typeArgs);
        }
        if (List.class.isAssignableFrom(clazz)) {
            return new ReflectionListEncoder(clazz, typeArgs);
        }
        if (Collection.class.isAssignableFrom(clazz)) {
            return new ReflectionCollectionEncoder(clazz, typeArgs);
        }
        if (Map.class.isAssignableFrom(clazz)) {
            return new ReflectionMapEncoder(clazz, typeArgs);
        }
        if (clazz.isEnum()) {
            return new ReflectionEnumEncoder(clazz);
        }
        return new ReflectionObjectEncoder(classInfo);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy