本文整理了Java中com.alibaba.fastjson.JSON.toJSONString()
方法的一些代码示例,展示了JSON.toJSONString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON.toJSONString()
方法的具体详情如下:
包路径:com.alibaba.fastjson.JSON
类名称:JSON
方法名:toJSONString
[英]This method serializes the specified object into its equivalent Json representation. Note that this method works fine if the any of the object fields are of generic type, just the object itself should not be of a generic type. If you want to write out the object to a Writer, use #writeJSONString(Writer,Object,SerializerFeature[]) instead.
[中]此方法将指定对象序列化为其等效的Json表示形式。请注意,如果任何对象字段都是泛型类型,则此方法可以正常工作,只是对象本身不应是泛型类型。如果要将对象写入写入器,请改用#writeJSONString(Writer,object,SerializerFeature[])。
代码示例来源:origin: alibaba/fastjson
public String toJSONString() {
return JSON.toJSONString(path);
}
}
代码示例来源:origin: alibaba/fastjson
public String toString() {
return JSON.toJSONString(this);
}
}
代码示例来源:origin: hs-web/hsweb-framework
@Override
public String toString() {
return JSON.toJSONString(this, SerializerFeature.PrettyFormat);
}
}
代码示例来源:origin: alibaba/canal
public static String marshalToString(Object obj) {
return JSON.toJSONString(obj); // 默认为UTF-8
}
代码示例来源:origin: alibaba/canal
public static String marshalToString(Object obj, SerializerFeature... features) {
return JSON.toJSONString(obj, features); // 默认为UTF-8
}
代码示例来源:origin: code4craft/webmagic
private String toString(Object object) {
if (object instanceof Map) {
return JSON.toJSONString(object);
} else {
return String.valueOf(object);
}
}
代码示例来源:origin: alibaba/canal
public void sync(Dml dml) {
logger.info("DML: {}", JSON.toJSONString(dml, SerializerFeature.WriteMapNullValue));
}
代码示例来源:origin: apache/incubator-dubbo
public static String toArgumentString(Object[] args) {
StringBuilder buf = new StringBuilder();
for (Object arg : args) {
if (buf.length() > 0) {
buf.append(Constants.COMMA_SEPARATOR);
}
if (arg == null || ReflectUtils.isPrimitives(arg.getClass())) {
buf.append(arg);
} else {
try {
buf.append(JSON.toJSONString(arg));
} catch (Exception e) {
logger.warn(e.getMessage(), e);
buf.append(arg);
}
}
}
return buf.toString();
}
}
代码示例来源:origin: apache/incubator-dubbo
public static String toArgumentString(Object[] args) {
StringBuilder buf = new StringBuilder();
for (Object arg : args) {
if (buf.length() > 0) {
buf.append(Constants.COMMA_SEPARATOR);
}
if (arg == null || ReflectUtils.isPrimitives(arg.getClass())) {
buf.append(arg);
} else {
try {
buf.append(JSON.toJSONString(arg));
} catch (Exception e) {
logger.warn(e.getMessage(), e);
buf.append(arg);
}
}
}
return buf.toString();
}
}
代码示例来源:origin: code4craft/webmagic
@Override
public void process(ResultItems resultItems, Task task) {
String path = this.path + PATH_SEPERATOR + task.getUUID() + PATH_SEPERATOR;
try {
PrintWriter printWriter = new PrintWriter(new FileWriter(getFile(path + DigestUtils.md5Hex(resultItems.getRequest().getUrl()) + ".json")));
printWriter.write(JSON.toJSONString(resultItems.getAll()));
printWriter.close();
} catch (IOException e) {
logger.warn("write file error", e);
}
}
}
代码示例来源:origin: alibaba/canal
private void produce(String topicName, int partition, FlatMessage flatMessage) throws ExecutionException,
InterruptedException {
ProducerRecord<String, String> record = new ProducerRecord<String, String>(topicName,
partition,
null,
JSON.toJSONString(flatMessage, SerializerFeature.WriteMapNullValue));
if (kafkaProperties.getTransaction()) {
producer2.send(record);
} else {
producer2.send(record).get();
}
}
代码示例来源:origin: alibaba/fastjson
@Override
protected Object convertToInternal(Object payload, MessageHeaders headers, Object conversionHint) {
// encode payload to json string
return JSON.toJSONString(payload, fastJsonConfig.getSerializeConfig(), fastJsonConfig.getSerializeFilters(),
fastJsonConfig.getDateFormat(), JSON.DEFAULT_GENERATE_FEATURE, fastJsonConfig.getSerializerFeatures());
}
}
代码示例来源:origin: hs-web/hsweb-framework
@Override
public DataAccessConfig create(DataAccessEntity entity) {
return dataAccessConfigBuilderFactory.create().fromJson(JSON.toJSONString(entity)).build();
}
}
代码示例来源:origin: alibaba/Sentinel
@Override
public CommandResponse<String> handle(CommandRequest request) {
String namespace = request.getParam("namespace");
if (StringUtil.isEmpty(namespace)) {
return CommandResponse.ofSuccess(JSON.toJSONString(ClusterParamFlowRuleManager.getAllParamRules()));
} else {
return CommandResponse.ofSuccess(JSON.toJSONString(ClusterParamFlowRuleManager.getParamRules(namespace)));
}
}
}
代码示例来源:origin: alibaba/Sentinel
@Override
public CommandResponse<String> handle(CommandRequest request) {
String namespace = request.getParam("namespace");
if (StringUtil.isEmpty(namespace)) {
return CommandResponse.ofFailure(new IllegalArgumentException("failed: namespace cannot be empty"));
}
return CommandResponse.ofSuccess(
JSON.toJSONString(ClusterMetricNodeGenerator.generateCurrentNodeMap(namespace))
);
}
}
代码示例来源:origin: code4craft/webmagic
private void setExtrasInItem(Jedis jedis,Request request, Task task)
{
if(request.getExtras() != null)
{
String field = DigestUtils.shaHex(request.getUrl());
String value = JSON.toJSONString(request);
jedis.hset(getItemKey(task), field, value);
}
}
代码示例来源:origin: hs-web/hsweb-framework
@Override
default PK saveOrUpdate(E e) {
return createRequest("/").requestBody(JSON.toJSONString(e)).patch().as(getPrimaryKeyType());
}
}
代码示例来源:origin: hs-web/hsweb-framework
@Override
default PK insert(E data) {
return createRequest("/").requestBody(JSON.toJSONString(data)).post().as(getPrimaryKeyType());
}
}
代码示例来源:origin: code4craft/webmagic
@Override
protected void pushWhenNoDuplicate(Request request, Task task) {
Jedis jedis = pool.getResource();
try {
jedis.rpush(getQueueKey(task), request.getUrl());
if (checkForAdditionalInfo(request)) {
String field = DigestUtils.shaHex(request.getUrl());
String value = JSON.toJSONString(request);
jedis.hset((ITEM_PREFIX + task.getUUID()), field, value);
}
} finally {
jedis.close();
}
}
代码示例来源:origin: hs-web/hsweb-framework
public DynamicFormDeployLogEntity createDeployLog(DynamicFormEntity form, List<DynamicFormColumnEntity> columns) {
DynamicFormDeployLogEntity entity = entityFactory.newInstance(DynamicFormDeployLogEntity.class);
entity.setStatus(DataStatus.STATUS_ENABLED);
entity.setDeployTime(System.currentTimeMillis());
entity.setVersion(form.getVersion());
entity.setFormId(form.getId());
DynamicFormColumnBindEntity bindEntity = new DynamicFormColumnBindEntity();
bindEntity.setForm(form);
bindEntity.setColumns(columns);
entity.setMetaData(JSON.toJSONString(bindEntity));
return entity;
}
内容来源于网络,如有侵权,请联系作者删除!