This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
ObjectSerializer_cn
wenshao edited this page May 4, 2016
·
6 revisions
fastjson提供了自定义序列化的接口,当你通过配置无法满足自定义序列化需求时,你可以使用ObjectSerializer接口。
package com.alibaba.fastjson.serializer;
public interface ObjectSerializer {
void write(JSONSerializer serializer,
Object object,
Object fieldName,
Type fieldType,
int features) throws IOException;
}
package com.alibaba.fastjson.serializer;
public class SerializeConfig {
public boolean put(Type key, ObjectSerializer value);
}
public class CharacterCodec implements ObjectSerializer {
public void write(JSONSerializer serializer,
Object object,
Object fieldName,
Type fieldType,
int features) throws IOException {
SerializeWriter out = serializer.out;
Character value = (Character) object;
if (value == null) {
out.writeString("");
return;
}
char c = value.charValue();
if (c == 0) {
out.writeString("\u0000");
} else {
out.writeString(value.toString());
}
}
}
如有需要修改本注脚,请联系阿里巴巴,
© Alibaba Fastjson Develop Team
注明: 版权所有阿里巴巴,请注明版权所有者
If you need to amend this footnote, please contact Alibaba.
© Alibaba Fastjson Develop Team
Note: Copyright Alibaba, please indicate the copyright owner