本文整理匯總了Java中org.codehaus.jackson.JsonGenerator.writeString方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonGenerator.writeString方法的具體用法?Java JsonGenerator.writeString怎麽用?Java JsonGenerator.writeString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jackson.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeAttribute
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
private static void writeAttribute(JsonGenerator jg, String attName, final String descriptionStr,
Object value)
throws IOException {
boolean description = false;
if (descriptionStr != null && descriptionStr.length() > 0 && !attName.equals(descriptionStr)) {
description = true;
jg.writeFieldName(attName);
jg.writeStartObject();
jg.writeFieldName("description");
jg.writeString(descriptionStr);
jg.writeFieldName("value");
writeObject(jg, description, value);
jg.writeEndObject();
} else {
jg.writeFieldName(attName);
writeObject(jg, description, value);
}
}
示例2: writeJsonFields
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
* Writes named schema in JSON format
*
* @param gen JSON generator
* @param names list of named schemas already written
* @param encSpace enclosing namespace of the schema
*/
@Override
protected void writeJsonFields(JsonGenerator gen, SchemaNames names, String encSpace) throws IOException {
_schemaName.writeJson(gen, names);
if (_doc != null && !_doc.isEmpty()) {
gen.writeFieldName("doc");
gen.writeString(_doc);
}
if (_aliases != null) {
gen.writeFieldName("aliases");
gen.writeStartArray();
for (SchemaName name : _aliases) {
String fullname = name.getSpace() != null ? name.getSpace() + "." + name.getName() : name.getName();
gen.writeString(fullname);
}
gen.writeEndArray();
}
}
示例3: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(VirtualNetwork vNet, JsonGenerator jGen,
SerializerProvider serializer) throws IOException,
JsonProcessingException {
jGen.writeStartObject();
jGen.writeStringField("name", vNet.name);
jGen.writeStringField("guid", vNet.guid);
jGen.writeStringField("gateway", vNet.gateway);
jGen.writeArrayFieldStart("mac");
Iterator<MACAddress> hit = vNet.hosts.iterator();
while (hit.hasNext())
jGen.writeString(hit.next().toString());
jGen.writeEndArray();
jGen.writeEndObject();
}
開發者ID:vishalshubham,項目名稱:Multipath-Hedera-system-in-Floodlight-controller,代碼行數:19,代碼來源:VirtualNetworkSerializer.java
示例4: writeObject
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
private void writeObject(JsonGenerator jg, Object value) throws IOException {
if(value == null) {
jg.writeNull();
} else {
Class<?> c = value.getClass();
if (c.isArray()) {
jg.writeStartArray();
int len = Array.getLength(value);
for (int j = 0; j < len; j++) {
Object item = Array.get(value, j);
writeObject(jg, item);
}
jg.writeEndArray();
} else if(value instanceof Number) {
Number n = (Number)value;
jg.writeNumber(n.toString());
} else if(value instanceof Boolean) {
Boolean b = (Boolean)value;
jg.writeBoolean(b);
} else if(value instanceof CompositeData) {
CompositeData cds = (CompositeData)value;
CompositeType comp = cds.getCompositeType();
Set<String> keys = comp.keySet();
jg.writeStartObject();
for(String key: keys) {
writeAttribute(jg, key, cds.get(key));
}
jg.writeEndObject();
} else if(value instanceof TabularData) {
TabularData tds = (TabularData)value;
jg.writeStartArray();
for(Object entry : tds.values()) {
writeObject(jg, entry);
}
jg.writeEndArray();
} else {
jg.writeString(value.toString());
}
}
}
示例5: toJson
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
* Build a JSON entry from the parameters. This is public for testing.
*
* @param writer destination
* @param loggerName logger name
* @param timeStamp time_t value
* @param level level string
* @param threadName name of the thread
* @param message rendered message
* @param ti nullable thrown information
* @return the writer
* @throws IOException on any problem
*/
public Writer toJson(final Writer writer,
final String loggerName,
final long timeStamp,
final String level,
final String threadName,
final String message,
final ThrowableInformation ti) throws IOException {
JsonGenerator json = factory.createJsonGenerator(writer);
json.writeStartObject();
json.writeStringField(NAME, loggerName);
json.writeNumberField(TIME, timeStamp);
Date date = new Date(timeStamp);
json.writeStringField(DATE, dateFormat.format(date));
json.writeStringField(LEVEL, level);
json.writeStringField(THREAD, threadName);
json.writeStringField(MESSAGE, message);
if (ti != null) {
//there is some throwable info, but if the log event has been sent over the wire,
//there may not be a throwable inside it, just a summary.
Throwable thrown = ti.getThrowable();
String eclass = (thrown != null) ?
thrown.getClass().getName()
: "";
json.writeStringField(EXCEPTION_CLASS, eclass);
String[] stackTrace = ti.getThrowableStrRep();
json.writeArrayFieldStart(STACK);
for (String row : stackTrace) {
json.writeString(row);
}
json.writeEndArray();
}
json.writeEndObject();
json.flush();
json.close();
return writer;
}
示例6: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
public void serialize(AnonymizableDataType object, JsonGenerator jGen,
SerializerProvider sProvider)
throws IOException, JsonProcessingException {
Object val = object.getAnonymizedValue(statePool, conf);
// output the data if its a string
if (val instanceof String) {
jGen.writeString(val.toString());
} else {
// let the mapper (JSON generator) handle this anonymized object.
jGen.writeObject(val);
}
}
示例7: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
public void serialize(DataType object, JsonGenerator jGen, SerializerProvider sProvider)
throws IOException, JsonProcessingException {
Object data = object.getValue();
if (data instanceof String) {
jGen.writeString(data.toString());
} else {
jGen.writeObject(data);
}
}
示例8: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(final MediaType mediaType, final JsonGenerator generator, final SerializerProvider provider)
throws IOException {
generator.writeStartObject();
generator.writeFieldName("name");
generator.writeString(mediaType.name());
generator.writeFieldName("displayName");
generator.writeString(mediaType.getDisplayName());
generator.writeEndObject();
}
示例9: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(Date arg0, JsonGenerator arg1,
SerializerProvider arg2) throws IOException,
JsonProcessingException {
arg1.writeString(DateFormatUtils.format(arg0, "yyyy-MM-dd HH:mm:ss", Locale.CHINA));
}
示例10: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(
final Interval interval,
final JsonGenerator jgen,
final SerializerProvider provider) throws IOException, JsonProcessingException
{
if (interval == null)
{
jgen.writeNull();
return;
}
jgen.writeString(interval.getStartMillis() + "-" + interval.getEndMillis());
}
示例11: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(
final Instant dateTime,
final JsonGenerator jgen,
final SerializerProvider provider) throws IOException, JsonProcessingException
{
if (dateTime == null)
{
jgen.writeNull();
return;
}
final DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
jgen.writeString(dateTime.toString(formatter));
}
示例12: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(
final Duration duration,
final JsonGenerator jgen,
final SerializerProvider provider) throws IOException, JsonProcessingException
{
if (duration == null)
{
jgen.writeNull();
return;
}
final PeriodFormatter formatter = ISOPeriodFormat.standard();
jgen.writeString(duration.toPeriod().toString(formatter));
}
示例13: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(
final LocalDate date,
final JsonGenerator jgen,
final SerializerProvider provider) throws IOException, JsonProcessingException
{
if (date == null)
{
jgen.writeNull();
return;
}
jgen.writeString(date.toString());
}
示例14: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
// get Picklist enum element class from array class
Class<?> arrayClass = value.getClass();
final Class<?> aClass = arrayClass.getComponentType();
try {
Method getterMethod = aClass.getMethod("value");
final int length = Array.getLength(value);
// construct a string of form value1;value2;...
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < length; i++) {
buffer.append((String) getterMethod.invoke(Array.get(value, i)));
if (i < (length - 1)) {
buffer.append(';');
}
}
jgen.writeString(buffer.toString());
} catch (Exception e) {
throw new JsonGenerationException(
String.format("Exception writing pick list value %s of type %s: %s",
value, value.getClass().getName(), e.getMessage()), e);
}
}
示例15: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(
PropertyInfo propertyInfo, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException
{
if (provideDescription) {
jgen.writeStartObject();
jgen.writeStringField("value", propertyInfo.value);
jgen.writeStringField("description", propertyInfo.description);
jgen.writeEndObject();
} else {
jgen.writeString(propertyInfo.value);
}
}