external.com.alibaba.fastjson.serializer.ListSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sekiro-api Show documentation
Show all versions of sekiro-api Show documentation
ratel api,used for developer on ratel system,an extension for xposed framewrok,ratel api compatable with original xposed framework
/*
* Copyright 1999-2101 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package external.com.alibaba.fastjson.serializer;
import external.com.alibaba.fastjson.util.TypeUtils;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.IdentityHashMap;
import java.util.List;
/**
* @author wenshao[[email protected]]
*/
public final class ListSerializer implements ObjectSerializer {
public final void write(JSONSerializer serializer, //
Object object, //
Object fieldName, //
Type fieldType) throws IOException {
SerializeWriter out = serializer.out;
boolean writeClassName = (out.features & SerializerFeature.WriteClassName.mask) != 0;
Type elementType = null;
if (writeClassName) {
elementType = TypeUtils.getCollectionItemType(fieldType);
}
if (object == null) {
if ((out.features & SerializerFeature.WriteNullListAsEmpty.mask) != 0) {
out.write("[]");
} else {
out.writeNull();
}
return;
}
List> list = (List>) object;
final int size = list.size();
if (size == 0) {
out.append("[]");
return;
}
SerialContext context = serializer.context;
// serializer.setContext(context, object, fieldName, 0);
if ((out.features & SerializerFeature.DisableCircularReferenceDetect.mask) == 0) {
serializer.context = new SerialContext(context, object, fieldName, 0);
if (serializer.references == null) {
serializer.references = new IdentityHashMap