Java Code Examples for com.alibaba.fastjson.serializer.JSONSerializer#getWriter()
The following examples show how to use
com.alibaba.fastjson.serializer.JSONSerializer#getWriter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastJsonIssue.java From actframework with Apache License 2.0 | 6 votes |
@Override public void write( JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features ) { SerializeWriter out = serializer.getWriter(); if (object == null) { out.writeNull(); } else { Class cls = object.getClass(); if (cls == DateTime.class) { out.writeString(object.toString()); } else { out.writeString(object.toString()); } } }
Example 2
Source File: FastJsonJodaDateCodec.java From actframework with Apache License 2.0 | 6 votes |
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { out.writeNull(); return; } Class cls = object.getClass(); if (cls == DateTime.class) { out.writeString(dateTimeCodec().toString((DateTime) object)); return; } else if (cls == LocalDateTime.class) { out.writeString(localDateTimeCodec().toString((LocalDateTime) object)); return; } else if (cls == LocalDate.class) { out.writeString(localDateCodec().toString((LocalDate) object)); return; } else if (cls == LocalTime.class) { out.writeString(localTimeCodec().toString((LocalTime) object)); return; } out.writeString(object.toString()); }
Example 3
Source File: HistogramSerializer.java From watcher with Apache License 2.0 | 6 votes |
@Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { Histogram histogram = (Histogram) object; SerializeWriter writer = serializer.getWriter(); final Snapshot snapshot = histogram.getSnapshot(); writer.writeFieldValue('{', "count", histogram.getCount()); writer.writeFieldValue(',', "max", snapshot.getMax()); writer.writeFieldValue(',', "mean", snapshot.getMean()); writer.writeFieldValue(',', "min", snapshot.getMin()); writer.writeFieldValue(',', "p50", snapshot.getMedian()); writer.writeFieldValue(',', "p75", snapshot.get75thPercentile()); writer.writeFieldValue(',', "p95", snapshot.get95thPercentile()); writer.writeFieldValue(',', "p98", snapshot.get98thPercentile()); writer.writeFieldValue(',', "p99", snapshot.get99thPercentile()); writer.writeFieldValue(',', "p999", snapshot.get999thPercentile()); writer.writeFieldValue(',', "stddev", snapshot.getStdDev()); writer.write('}'); }
Example 4
Source File: MyNumberFieldSerializer.java From dpCms with Apache License 2.0 | 6 votes |
@Override public void writeValue(JSONSerializer serializer, Object propertyValue) throws Exception { SerializeWriter out = serializer.getWriter(); Object value = propertyValue; if (value == null) { if (out.isEnabled(SerializerFeature.WriteNullNumberAsZero)) { out.write('0'); } else { out.writeNull(); } return; } out.append(value.toString()); }
Example 5
Source File: DoubleCustomSerializer.java From phone with Apache License 2.0 | 6 votes |
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { out.write('0'); return; } double doubleValue = ((Double) object).doubleValue(); if (Double.isNaN(doubleValue)||Double.isInfinite(doubleValue)) { out.write('0'); } else { String doubleText = Double.toString(doubleValue); NumberUtil.decimal(doubleText, digits, fullZero); out.append(doubleText); if (serializer.isEnabled(SerializerFeature.WriteClassName)) { out.write('D'); } } }
Example 6
Source File: TimerSerializer.java From watcher with Apache License 2.0 | 6 votes |
@Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { Timer timer = (Timer) object; final Snapshot snapshot = timer.getSnapshot(); SerializeWriter writer = serializer.getWriter(); writer.writeFieldValue('{', "count", timer.getCount()); writer.writeFieldValue(',', "max", snapshot.getMax() * durationFactor); writer.writeFieldValue(',', "mean", snapshot.getMean() * durationFactor); writer.writeFieldValue(',', "min", snapshot.getMin() * durationFactor); writer.writeFieldValue(',', "p50", snapshot.getMedian() * durationFactor); writer.writeFieldValue(',', "p75", snapshot.get75thPercentile() * durationFactor); writer.writeFieldValue(',', "p95", snapshot.get95thPercentile() * durationFactor); writer.writeFieldValue(',', "p98", snapshot.get98thPercentile() * durationFactor); writer.writeFieldValue(',', "p99", snapshot.get99thPercentile() * durationFactor); writer.writeFieldValue(',', "p999", snapshot.get999thPercentile() * durationFactor); writer.writeFieldValue(',', "stddev", snapshot.getStdDev() * durationFactor); writer.writeFieldValue(',', "m15_rate", timer.getFifteenMinuteRate() * rateFactor); writer.writeFieldValue(',', "m1_rate", timer.getOneMinuteRate() * rateFactor); writer.writeFieldValue(',', "m5_rate", timer.getFiveMinuteRate() * rateFactor); writer.writeFieldValue(',', "mean_rate", timer.getMeanRate() * rateFactor); writer.writeFieldValue(',', "duration_units", durationUnit); writer.writeFieldValue(',', "rate_units", rateUnit); writer.write('}'); }
Example 7
Source File: BackupShardSerializer.java From joyrpc with Apache License 2.0 | 6 votes |
@Override public void write(final JSONSerializer serializer, final Object object, final Object fieldName, final Type fieldType, final int features) throws IOException { if (object == null) { serializer.writeNull(); } else { SerializeWriter out = serializer.getWriter(); out.write('{'); BackupShard backupShard = (BackupShard) object; writeString(out, "name", backupShard.getName()); writeString(out, "region", backupShard.getRegion()); writeString(out, "dataCenter", backupShard.getDataCenter()); writeString(out, "protocol", backupShard.getProtocol()); writeString(out, "address", backupShard.getAddress()); out.writeFieldName("weight"); out.writeInt(backupShard.getWeight()); out.write('}'); } }
Example 8
Source File: TreeSerializer.java From java-platform with Apache License 2.0 | 6 votes |
@Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { out.writeNull(); return; } Tree<?> tree = (Tree<?>) object; if (tree.isCheckable()) { visitCheck(tree.getRoots(), tree.getChecked()); } if (!Strings.isNullOrEmpty(tree.getIconProperty())) { visitIcon(tree.getRoots(), tree.getIconProperty()); } if (tree.isExpandAll()) { expandAll(tree.getRoots()); } serializer.write(tree.getRoots()); }
Example 9
Source File: PageSerializer.java From java-platform with Apache License 2.0 | 5 votes |
@Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { out.writeNull(); return; } Page<?> page = (Page<?>) object; out.write('{'); out.writeFieldName(DEFAULT_CURRENT_FIELD); out.writeInt(page.getNumber()); out.write(','); out.writeFieldName(DEFAULT_ROWCOUNT_FIELD); out.writeInt(page.getSize()); out.write(','); out.writeFieldName(DEFAULT_TOTAL_FIELD); out.writeLong(page.getTotalElements()); out.write(','); out.writeFieldName(DEFAULT_ROWS_FIELD); serializer.write(page.getContent()); out.write('}'); }
Example 10
Source File: FastJsonValueObjectSerializer.java From actframework with Apache License 2.0 | 5 votes |
@Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { out.writeNull(); return; } ValueObject vo = (ValueObject) object; out.write(vo.toJSONString()); }
Example 11
Source File: MeterSerializer.java From watcher with Apache License 2.0 | 5 votes |
@Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { Meter meter = (Meter) object; SerializeWriter writer = serializer.getWriter(); writer.writeFieldValue('{', "count", meter.getCount()); writer.writeFieldValue(',', "m15_rate", meter.getFifteenMinuteRate() * rateFactor); writer.writeFieldValue(',', "m1_rate", meter.getOneMinuteRate() * rateFactor); writer.writeFieldValue(',', "m5_rate", meter.getFiveMinuteRate() * rateFactor); writer.writeFieldValue(',', "mean_rate", meter.getMeanRate() * rateFactor); writer.writeFieldValue(',', "units", rateUnit); writer.write('}'); }
Example 12
Source File: GaugeSerializer.java From watcher with Apache License 2.0 | 5 votes |
@Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { Gauge gauge = (Gauge) object; Object value = gauge.getValue(); SerializeWriter writer = serializer.getWriter(); if (value == null) writer.write("0"); else writer.write(value.toString()); }
Example 13
Source File: JodaDateTimeSerializer.java From java-platform with Apache License 2.0 | 5 votes |
@Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { out.writeNull(); return; } DateTime dateTime = (DateTime) object; serializer.write(dateTime.toDate()); }
Example 14
Source File: BigDecimalCustomSerializer.java From phone with Apache License 2.0 | 5 votes |
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { out.write('0'); return; } BigDecimal val = (BigDecimal) object; String value = val.toString(); out.write(NumberUtil.decimal(value, digits, fullZero)); if (out.isEnabled(SerializerFeature.WriteClassName) && fieldType != BigDecimal.class && val.scale() == 0) { out.write('.'); } }
Example 15
Source File: MyFieldSerializer.java From dpCms with Apache License 2.0 | 5 votes |
public void writePrefix(JSONSerializer serializer) throws IOException { SerializeWriter out = serializer.getWriter(); if (serializer.isEnabled(SerializerFeature.QuoteFieldNames)) { if (serializer.isEnabled(SerializerFeature.UseSingleQuotes)) { out.write(single_quoted_fieldPrefix); } else { out.write(double_quoted_fieldPrefix); } } else { out.write(un_quoted_fieldPrefix); } }
Example 16
Source File: SwaggerJsonSerializer.java From uavstack with Apache License 2.0 | 5 votes |
public void write(JSONSerializer serializer, // Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); Json json = (Json) object; String value = json.value(); out.write(value); }
Example 17
Source File: ObjectTypeAdapter.java From java-unified-sdk with Apache License 2.0 | 5 votes |
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException { AVObject avObject = (AVObject)object; SerializeWriter writer = serializer.getWriter(); writer.write('{'); // for 1.1.70.android fastjson, we dont use writer.writeFieldValue(seperator, field, value) method. writer.write(' '); // writer.writeFieldName("@type", false); // writer.writeString(avObject.getClass().getName()); // writer.write(','); writer.writeFieldName(KEY_VERSION, false); writer.writeString(DEFAULT_VERSION); writer.write(','); writer.writeFieldName(AVObject.KEY_CLASSNAME, false); writer.writeString(avObject.getClassName()); writer.write(','); writer.writeFieldName(KEY_SERVERDATA, false); if (AVOSCloud.isEnableCircularReferenceDetect()) { writer.write(JSON.toJSONString(avObject.serverData, ObjectValueFilter.instance, SerializerFeature.WriteClassName)); } else { writer.write(JSON.toJSONString(avObject.serverData, ObjectValueFilter.instance, SerializerFeature.WriteClassName, SerializerFeature.DisableCircularReferenceDetect)); } writer.write('}'); }
Example 18
Source File: AbstractSerializer.java From joyrpc with Apache License 2.0 | 5 votes |
/** * 写值 * * @param serializer 输出 * @param field 字段 * @param value 值 * @param ignoreNull 是否忽略null值 * @param separator 分隔符位置 */ protected void write(final JSONSerializer serializer, final String field, final Object value, final boolean ignoreNull, final int separator) { if (value != null || !ignoreNull) { SerializeWriter out = serializer.getWriter(); if (separator == BEFORE) { out.write(','); } out.writeFieldName(field); serializer.write(value); if (separator == AFTER) { out.write(','); } } }
Example 19
Source File: ResultSerializer.java From java-platform with Apache License 2.0 | 4 votes |
@Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { out.writeNull(); return; } Result result = (Result) object; out.write('{'); Map<String, Object> extraProperties = result.getExtraProperties(); for (Entry<String, Object> entry : extraProperties.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); out.writeFieldName(key); serializer.write(value); out.write(','); } out.writeFieldName(FIELD_SUCCESS); out.write(Objects.equal(result.getCode(), Code.success)); out.write(','); out.writeFieldName(FIELD_CODE); out.writeString(result.getCode().name()); out.write(','); out.writeFieldName(FIELD_MESSAGE); out.writeString(result.getMessage()); out.write(','); out.writeFieldName(FIELD_DATA); serializer.write(result.getData()); out.write('}'); }
Example 20
Source File: NodeSerializer.java From java-platform with Apache License 2.0 | 4 votes |
@Override public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { SerializeWriter out = serializer.getWriter(); if (object == null) { out.writeNull(); return; } Node<?> node = (Node<?>) object; out.write('{'); out.writeFieldName("children"); serializer.write(node.getChildren()); out.write(","); out.writeFieldName("leaf"); out.write(node.getLeaf()); out.write(","); if (!Strings.isNullOrEmpty(node.getIcon())) { out.writeFieldName("icon"); out.writeString(node.getIcon()); out.write(","); } if (node.getChecked() != null) { out.writeFieldName("checked"); out.write(node.getChecked()); out.write(","); } if (node.getExpanded() != null) { out.writeFieldName("expanded"); out.write(node.getExpanded()); out.write(","); } List<? extends SerializeFilter> serializeFilters = serializer.getPropertyPreFilters(); Object data = node.getData(); // 处理父节点 if (data != null && data instanceof Treeable && serializeFilters != null && serializeFilters.size() > 0) { boolean parentProcess = false; for (SerializeFilter filter : serializeFilters) { if (filter instanceof IncludesPropertyPreFilter) { Set<String> includes = ((IncludesPropertyPreFilter) filter).getIncludes(); parentProcess = includes.contains("parent"); if (parentProcess) { break; } } } if (parentProcess) { Object parent = ((Treeable<?>) data).getParent(); if (parent != null) { out.writeFieldName("parent"); out.write(JSON.toJSONString(parent, serializeConfig, Iterables.toArray(serializeFilters, SerializeFilter.class))); out.write(","); } } } // 处理对象值 String dataString = serializeFilters == null ? JSON.toJSONString(data, serializeConfig) : JSON.toJSONString(data, serializeConfig, Iterables.toArray(serializeFilters, SerializeFilter.class)); dataString = StringUtils.substring(dataString, 1); out.write(dataString); }