Rabbit-R1/switch port/java/sources/com/alibaba/fastjson/serializer/StringCodec.java

31 lines
1 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package com.alibaba.fastjson.serializer;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import java.io.IOException;
import java.lang.reflect.Type;
/* loaded from: classes2.dex */
public class StringCodec implements ObjectSerializer, ObjectDeserializer {
public static StringCodec instance = new StringCodec();
private StringCodec() {
}
@Override // com.alibaba.fastjson.serializer.ObjectSerializer
public void write(JSONSerializer jSONSerializer, Object obj, Object obj2, Type type) throws IOException {
String str = (String) obj;
SerializeWriter serializeWriter = jSONSerializer.out;
if (str == null) {
serializeWriter.writeNull();
} else {
serializeWriter.writeString(str);
}
}
@Override // com.alibaba.fastjson.parser.deserializer.ObjectDeserializer
public <T> T deserialze(DefaultJSONParser defaultJSONParser, Type type, Object obj) {
return (T) defaultJSONParser.parseString();
}
}