需要用到有序的JSONObject对象时(比如生成摘要用到加密)
入参:param
出参:logParam
引用
import com.alibaba.fastjson.parser.Feature;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
代码
FeatureAccessoriesEntity featureAccessoriesEntity = JSONObject.toJavaObject(param, FeatureAccessoriesEntity.class);
String logStr = new ObjectMapper().writeValueAsString(featureAccessoriesEntity);
JSONObject logParam = JSONObject.parseObject(logStr, Feature.OrderedField);
文章讲述了在处理需要有序JSONObject的情况,如用于加密摘要时,如何将参数(param)转换为FeatureAccessoriesEntity对象,然后利用Jackson的ObjectMapper将其转化为字符串(logStr),最后通过JSONObject的parseObject方法,基于Feature.OrderedField创建了一个保持顺序的logParam对象。
1999

被折叠的 条评论
为什么被折叠?



