com.alibaba.fastjson2.writer.ObjectWriters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastjson2 Show documentation
Show all versions of fastjson2 Show documentation
Fastjson is a JSON processor (JSON parser + JSON generator) written in Java
package com.alibaba.fastjson2.writer;
import com.alibaba.fastjson2.codec.FieldInfo;
import com.alibaba.fastjson2.function.*;
import com.alibaba.fastjson2.util.ParameterizedTypeImpl;
import com.alibaba.fastjson2.util.TypeUtils;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.List;
public class ObjectWriters {
static ObjectWriterCreator INSTANCE = ObjectWriterCreator.INSTANCE;
public static ObjectWriter ofReflect(Class objectType) {
return ObjectWriterCreator.INSTANCE.createObjectWriter(objectType);
}
public static ObjectWriter objectWriter(Class objectType) {
return INSTANCE.createObjectWriter(objectType);
}
public static ObjectWriter objectWriter(Class objectType, FieldWriter... fieldWriters) {
return INSTANCE.createObjectWriter(objectType, fieldWriters);
}
public static ObjectWriter of(Class objectType, FieldWriter... fieldWriters) {
return INSTANCE.createObjectWriter(objectType, fieldWriters);
}
public static ObjectWriter objectWriter(Class objectType, long features, FieldWriter... fieldWriters) {
return INSTANCE.createObjectWriter(objectType, features, fieldWriters);
}
public static ObjectWriter objectWriter(FieldWriter... fieldWriters) {
return INSTANCE.createObjectWriter(fieldWriters);
}
public static ObjectWriter ofToString(Function function) {
return INSTANCE.createObjectWriter(
INSTANCE.createFieldWriter(
null,
null,
"toString",
0,
FieldInfo.VALUE_MASK,
null,
null,
String.class,
String.class,
null,
function
)
);
}
public static ObjectWriter ofToInt(ToIntFunction function) {
return INSTANCE.createObjectWriter(
new FieldWriterInt32ValFunc(
"toInt",
0,
FieldInfo.VALUE_MASK,
null,
null,
null,
function
)
);
}
public static ObjectWriter ofToLong(ToLongFunction function) {
return INSTANCE.createObjectWriter(
new FieldWriterInt64ValFunc(
"toLong",
0,
FieldInfo.VALUE_MASK,
null,
null,
null,
function
)
);
}
public static ObjectWriter ofToByteArray(Function