com.firefly.utils.json.parser.ArrayParser Maven / Gradle / Ivy
package com.firefly.utils.json.parser;
import com.firefly.utils.ReflectUtils;
import com.firefly.utils.exception.CommonRuntimeException;
import com.firefly.utils.json.JsonReader;
import com.firefly.utils.json.Parser;
import com.firefly.utils.json.exception.JsonException;
import com.firefly.utils.json.support.ParserMetaInfo;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
public class ArrayParser implements Parser {
private ParserMetaInfo elementMetaInfo;
public ArrayParser(Class> clazz) {
elementMetaInfo = new ParserMetaInfo();
elementMetaInfo.setType(clazz);
elementMetaInfo.setParser(ParserStateMachine.getParser(clazz, null));
}
@Override
public Object convertTo(JsonReader reader, Class> clazz) throws IOException {
if (reader.isNull())
return null;
if (!reader.isArray())
throw new JsonException("json string is not array format");
if (reader.isEmptyArray())
return Array.newInstance(elementMetaInfo.getType(), 0);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy