本文整理了Java中com.alibaba.fastjson.JSON.toJSONBytes()
方法的一些代码示例,展示了JSON.toJSONBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON.toJSONBytes()
方法的具体详情如下:
包路径:com.alibaba.fastjson.JSON
类名称:JSON
方法名:toJSONBytes
暂无
代码示例来源:origin: alibaba/canal
public static byte[] marshalToByte(Object obj, SerializerFeature... features) {
return JSON.toJSONBytes(obj, features); // 默认为UTF-8
}
代码示例来源:origin: alibaba/canal
public static byte[] marshalToByte(Object obj) {
return JSON.toJSONBytes(obj); // 默认为UTF-8
}
代码示例来源:origin: com.alibaba/fastjson
/**
* @since 1.2.11
*/
public static byte[] toJSONBytes(Object object, SerializeConfig config, int defaultFeatures, SerializerFeature... features) {
return toJSONBytes(object, config, emptyFilters, defaultFeatures, features);
}
代码示例来源:origin: com.alibaba/fastjson
/**
* @since 1.2.42
*/
public static byte[] toJSONBytes(Object object, SerializeConfig config, SerializerFeature... features) {
return toJSONBytes(object, config, emptyFilters, DEFAULT_GENERATE_FEATURE, features);
}
代码示例来源:origin: com.alibaba/fastjson
/**
* @since 1.2.42
*/
public static byte[] toJSONBytes(Object object, SerializeConfig config, SerializeFilter[] filters, int defaultFeatures, SerializerFeature... features) {
return toJSONBytes(object, config, filters, null, defaultFeatures, features);
}
代码示例来源:origin: com.alibaba/fastjson
/**
* @since 1.2.11
*/
public static byte[] toJSONBytes(Object object, int defaultFeatures, SerializerFeature... features) {
return toJSONBytes(object, SerializeConfig.globalInstance, defaultFeatures, features);
}
代码示例来源:origin: com.alibaba/fastjson
/**
* @since 1.2.42
*/
public static byte[] toJSONBytes(Object object, SerializeFilter[] filters, SerializerFeature... features) {
return toJSONBytes(object, SerializeConfig.globalInstance, filters, DEFAULT_GENERATE_FEATURE, features);
}
代码示例来源:origin: com.alibaba/fastjson
public static byte[] toJSONBytes(Object object, SerializerFeature... features) {
return toJSONBytes(object, DEFAULT_GENERATE_FEATURE, features);
}
代码示例来源:origin: com.alibaba/fastjson
public static byte[] toJSONBytes(Object object, SerializeFilter filter, SerializerFeature... features) {
return toJSONBytes(object, SerializeConfig.globalInstance, new SerializeFilter[] {filter}, DEFAULT_GENERATE_FEATURE, features);
}
代码示例来源:origin: com.alibaba/fastjson
public static byte[] toJSONBytes(Object object, SerializeConfig config, SerializeFilter filter, SerializerFeature... features) {
return toJSONBytes(object, config, new SerializeFilter[] {filter}, DEFAULT_GENERATE_FEATURE, features);
}
代码示例来源:origin: alibaba/fastjson
public byte[] serialize(Object object) throws SerializationException {
if (object == null) {
return new byte[0];
}
try {
return JSON.toJSONBytes(object, SerializerFeature.WriteClassName);
} catch (Exception ex) {
throw new SerializationException("Could not serialize: " + ex.getMessage(), ex);
}
}
代码示例来源:origin: com.alibaba/fastjson
public byte[] serialize(Object object) throws SerializationException {
if (object == null) {
return new byte[0];
}
try {
return JSON.toJSONBytes(object, SerializerFeature.WriteClassName);
} catch (Exception ex) {
throw new SerializationException("Could not serialize: " + ex.getMessage(), ex);
}
}
代码示例来源:origin: alibaba/fastjson
public RequestBody convert(T value) throws IOException {
try {
byte[] content = JSON.toJSONBytes(fastJsonConfig.getCharset()
, value
, fastJsonConfig.getSerializeConfig()
, fastJsonConfig.getSerializeFilters()
, fastJsonConfig.getDateFormat()
, JSON.DEFAULT_GENERATE_FEATURE
, fastJsonConfig.getSerializerFeatures()
);
return RequestBody.create(MEDIA_TYPE, content);
} catch (Exception e) {
throw new IOException("Could not write JSON: " + e.getMessage(), e);
}
}
}
代码示例来源:origin: com.alibaba/fastjson
public RequestBody convert(T value) throws IOException {
try {
byte[] content = JSON.toJSONBytes(fastJsonConfig.getCharset()
, value
, fastJsonConfig.getSerializeConfig()
, fastJsonConfig.getSerializeFilters()
, fastJsonConfig.getDateFormat()
, JSON.DEFAULT_GENERATE_FEATURE
, fastJsonConfig.getSerializerFeatures()
);
return RequestBody.create(MEDIA_TYPE, content);
} catch (Exception e) {
throw new IOException("Could not write JSON: " + e.getMessage(), e);
}
}
}
代码示例来源:origin: alibaba/fastjson
@Override
public byte[] serialize(T t) throws SerializationException {
if (t == null) {
return new byte[0];
}
try {
return JSON.toJSONBytes(
fastJsonConfig.getCharset(),
t,
fastJsonConfig.getSerializeConfig(),
fastJsonConfig.getSerializeFilters(),
fastJsonConfig.getDateFormat(),
JSON.DEFAULT_GENERATE_FEATURE,
fastJsonConfig.getSerializerFeatures()
);
} catch (Exception ex) {
throw new SerializationException("Could not serialize: " + ex.getMessage(), ex);
}
}
代码示例来源:origin: com.alibaba/fastjson
@Override
public byte[] serialize(T t) throws SerializationException {
if (t == null) {
return new byte[0];
}
try {
return JSON.toJSONBytes(
fastJsonConfig.getCharset(),
t,
fastJsonConfig.getSerializeConfig(),
fastJsonConfig.getSerializeFilters(),
fastJsonConfig.getDateFormat(),
JSON.DEFAULT_GENERATE_FEATURE,
fastJsonConfig.getSerializerFeatures()
);
} catch (Exception ex) {
throw new SerializationException("Could not serialize: " + ex.getMessage(), ex);
}
}
代码示例来源:origin: com.alibaba/fastjson
/**
* @since 1.2.55
*/
public static byte[] toJSONBytes(Charset charset, //
Object object, //
SerializeConfig config, //
SerializeFilter[] filters, //
String dateFormat, //
int defaultFeatures, //
SerializerFeature... features) {
SerializeWriter out = new SerializeWriter(null, defaultFeatures, features);
try {
JSONSerializer serializer = new JSONSerializer(out, config);
if (dateFormat != null && dateFormat.length() != 0) {
serializer.setDateFormat(dateFormat);
serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
}
if (filters != null) {
for (SerializeFilter filter : filters) {
serializer.addFilter(filter);
}
}
serializer.write(object);
return out.toBytes(charset);
} finally {
out.close();
}
}
代码示例来源:origin: hengyunabc/xdiamond
/**
* 对象会被转为json byte[]
*
* @param object
* @return
*/
public MessageBuilder jsonData(Object object) {
message.setData(JSON.toJSONBytes(object, SerializerFeature.DisableCircularReferenceDetect));
return this;
}
代码示例来源:origin: httl/httl
public byte[] toBytes(String key, Object value) {
if (value == null) {
return null;
}
if (isJsonWithClass()) {
return JSON.toJSONBytes(value, FEATURES_WITH_CLASS);
}
return JSON.toJSONBytes(value, FEATURES);
}
代码示例来源:origin: ucarGroup/DataLink
@Override
public void updatePosition(String taskId, Position position) {
DLinkZkUtils zkUtils = DLinkZkUtils.get();
String path = DLinkZkPathDef.getTaskPositionNode(taskId);
byte[] data = JSON.toJSONBytes(position, SerializerFeature.WriteClassName);
try {
zkUtils.zkClient().writeData(path, data);
} catch (ZkNoNodeException e) {
zkUtils.zkClient().createPersistent(path, data, true);// 第一次节点不存在,则尝试创建
}
}
内容来源于网络,如有侵权,请联系作者删除!