public abstract class TemplateSerializer<T> implements ObjectSerializer {
public abstract void write0(JSONSerializer serializer, T object, Object fieldName, Type fieldType, int features) throws IOException;
@Override
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
write0(serializer, (T) object, fieldName, fieldType, features);
}
}
public class ByteArraySerializer extends TemplateSerializer<byte[]> {
@Override
public void write0(JSONSerializer serializer, byte[] object, Object fieldName, Type fieldType, int features) throws IOException {
serializer.getWriter().writeHex(object);
}
}
public static void main(String[] args) {
Model model = new Model();
model.bytes = new byte[]{1, 3, 5};
SerializeConfig config = new SerializeConfig();
config.put(byte[].class, new ByteArraySerializer());
String str = JSONObject.toJSONString(model, config);
System.out.println("str = " + str);
System.exit(0);
}
str = {"bytes":x'010305'}