本文整理汇总了Java中com.alibaba.fastjson.serializer.SerializeFilter类的典型用法代码示例。如果您正苦于以下问题:Java SerializeFilter类的具体用法?Java SerializeFilter怎么用?Java SerializeFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializeFilter类属于com.alibaba.fastjson.serializer包,在下文中一共展示了SerializeFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJSONString
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
public static final String toJSONString(Object object, SerializeFilter filter, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
for (SerializerFeature feature : features) {
serializer.config(feature, true);
}
serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
setFilter(serializer, filter);
serializer.write(object);
String serializeWriter = out.toString();
return serializeWriter;
} finally {
out.close();
}
}
示例2: createSuccessResponse
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
public static String createSuccessResponse(Integer httpCode, Object result, SerializerFeature serializerFeature, SerializeFilter filter, HttpServletResponse response){
PrintWriter printWriter = null;
String jsonString = "";
try {
response.setCharacterEncoding(RESPONSE_CHARACTERENCODING);
response.setContentType(RESPONSE_CONTENTTYPE);
response.setStatus(httpCode);
printWriter = response.getWriter();
if(null != result){
if(null!=filter){
jsonString = JSONObject.toJSONString(result,filter,serializerFeature);
}else{
// jsonString = JSONObject.toJSONString(result, serializerFeature);
jsonString = JSONObject.toJSONStringWithDateFormat(result,"yyyy-MM-dd HH:ss:mm",serializerFeature);
}
printWriter.write(jsonString);
}
printWriter.flush();
} catch (Exception e) {
log.error("createResponse failed", e);
} finally {
if(null!=printWriter)printWriter.close();
}
return jsonString;
}
示例3: test_enum
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
public void test_enum() throws Exception {
Model model = new Model();
model.t1 = Type.A;
model.t2 = null;
ValueFilter valueFilter = new ValueFilter() {
public Object process(Object object, String name, Object value) {
return value;
}
};
SerializeFilter[] filters = {valueFilter};
String text = JSON.toJSONString(model, SerializeConfig.getGlobalInstance(), //
filters,
null,
0, //
SerializerFeature.QuoteFieldNames, //
SerializerFeature.BrowserCompatible, //
SerializerFeature.WriteEnumUsingName);
Assert.assertEquals("{\"t1\":\"A\"}", text);
}
示例4: setFilter
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
private static void setFilter(JSONSerializer serializer, SerializeFilter filter) {
if (filter != null) {
if (filter instanceof PropertyPreFilter) {
serializer.getPropertyPreFilters().add((PropertyPreFilter) filter);
}
if (filter instanceof NameFilter) {
serializer.getNameFilters().add((NameFilter) filter);
}
if (filter instanceof ValueFilter) {
serializer.getValueFilters().add((ValueFilter) filter);
}
if (filter instanceof PropertyFilter) {
serializer.getPropertyFilters().add((PropertyFilter) filter);
}
if (filter instanceof BeforeFilter) {
serializer.getBeforeFilters().add((BeforeFilter) filter);
}
if (filter instanceof AfterFilter) {
serializer.getAfterFilters().add((AfterFilter) filter);
}
}
}
示例5: toJSONString
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
public static final String toJSONString(Object object, SerializeFilter filter, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
serializer.config(feature, true);
}
serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
setFilter(serializer, filter);
serializer.write(object);
return out.toString();
} finally {
out.close();
}
}
示例6: addSerializeFilter
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
@Deprecated
public void addSerializeFilter(SerializeFilter filter) {
if (filter == null) {
return;
}
int length = this.fastJsonConfig.getSerializeFilters().length;
SerializeFilter[] filters = new SerializeFilter[length + 1];
System.arraycopy(this.fastJsonConfig.getSerializeFilters(), 0, filters, 0, length);
filters[filters.length - 1] = filter;
this.fastJsonConfig.setSerializeFilters(filters);
}
示例7: FastJsonConfig
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
/**
* init param.
*/
public FastJsonConfig() {
this.charset = Charset.forName("UTF-8");
this.serializeConfig = SerializeConfig.getGlobalInstance();
this.parserConfig = new ParserConfig();
this.serializerFeatures = new SerializerFeature[] {
SerializerFeature.BrowserSecure
};
this.serializeFilters = new SerializeFilter[0];
this.features = new Feature[0];
}
示例8: test_context_value_filter_not_effected
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
@Test
public void test_context_value_filter_not_effected () {
List<Object> params = new ArrayList<Object>();
Map data = new HashMap();
data.put("name", "ace");
params.add(data);
//fail Actual :[{"name":"ace"}]
Assert.assertEquals("[{\"name\":\"mark-ace\"}]", JSON.toJSONString(params,
new SerializeFilter[]{
contextValueFilter
})
);
}
示例9: test_context_value_filter_effected
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
@Test
public void test_context_value_filter_effected() {
List<Object> params = new ArrayList<Object>();
Map data = new HashMap();
data.put("name", "ace");
params.add(data);
//success
Assert.assertEquals("[{\"name\":\"mark-ace\"}]", JSON.toJSONString(params,
new SerializeFilter[]{
contextValueFilter,
valueFilter
})
);
}
示例10: test_for_issue
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
public void test_for_issue() throws Exception {
Map map = Collections.singletonMap("value", 123);
String json = JSON.toJSONString(map
, SerializeConfig.globalInstance
, new SerializeFilter[0]
, null
, JSON.DEFAULT_GENERATE_FEATURE & ~SerializerFeature.QuoteFieldNames.mask
);
assertEquals("{value:123}", json);
}
示例11: test_for_bug
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
public void test_for_bug() throws Exception {
ContactTemplateParam param = new ContactTemplateParam();
param.setAuditStatus(AuditStatusType.AUDIT_FAILURE);
String json = JSON.toJSONString(param, new SerializeFilter[] { new IntEnumFilter("auditStatus") });
assertEquals("{\"auditStatus\":0}", json);
}
示例12: test_for_issue
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
public void test_for_issue() throws Exception {
VO vo = new VO();
SerializeFilter filter = null;
JSON.toJSONString(vo, SerializeConfig.getGlobalInstance(), filter);
JSON.toJSONString(vo, SerializeConfig.getGlobalInstance(), new SerializeFilter[0]);
}
示例13: thin
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
public String thin(Object bean) {
toJSONString(bean, new SerializeFilter[]{firstValueFilter});
val ret = toJSONString(bean,
new SerializeFilter[]{nameFilter, secondValueFilter},
WriteMapNullValue);
this.keyMapping = WestJsonUtils.invert(innerKeyMapping);
this.valueMapping = WestJsonUtils.invert(innerValueMapping);
return ret;
}
示例14: setFilter
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
private static void setFilter(JSONSerializer serializer, SerializeFilter filter) {
if (filter == null) {
return;
}
if (filter instanceof PropertyPreFilter) {
serializer.getPropertyPreFilters().add((PropertyPreFilter) filter);
}
if (filter instanceof NameFilter) {
serializer.getNameFilters().add((NameFilter) filter);
}
if (filter instanceof ValueFilter) {
serializer.getValueFilters().add((ValueFilter) filter);
}
if (filter instanceof PropertyFilter) {
serializer.getPropertyFilters().add((PropertyFilter) filter);
}
if (filter instanceof BeforeFilter) {
serializer.getBeforeFilters().add((BeforeFilter) filter);
}
if (filter instanceof AfterFilter) {
serializer.getAfterFilters().add((AfterFilter) filter);
}
}
示例15: fastjsonFilters
import com.alibaba.fastjson.serializer.SerializeFilter; //导入依赖的package包/类
public SerializeFilter[] fastjsonFilters() {
if (null == fastjsonFilters) {
return null;
}
int len = fastjsonFilters.length;
SerializeFilter[] filters = new SerializeFilter[len];
for (int i = 0; i < len; ++i) {
filters[i] = app().getInstance(fastjsonFilters[i]);
}
return filters;
}