當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonGenerator.writeString方法代碼示例

本文整理匯總了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);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:19,代碼來源:JSONBean.java

示例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();
    }
}
 
開發者ID:archcentric,項目名稱:BaijiSerializer4J,代碼行數:27,代碼來源:NamedSchema.java

示例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());
    }
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:41,代碼來源:JMXJsonServlet.java

示例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;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:50,代碼來源:Log4Json.java

示例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);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:13,代碼來源:DefaultAnonymizingRumenSerializer.java

示例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);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:10,代碼來源:DefaultRumenSerializer.java

示例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();
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:11,代碼來源:MediaTypeSerializer.java

示例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));
    
}
 
開發者ID:javen-hao,項目名稱:osmp,代碼行數:8,代碼來源:DefaultObjectMapper.java

示例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());
}
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:15,代碼來源:IntervalSerializer.java

示例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));
}
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:16,代碼來源:InstantSerializer.java

示例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));
}
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:16,代碼來源:DurationSerializer.java

示例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());
}
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:15,代碼來源:LocalDateSerializer.java

示例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);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:30,代碼來源:MultiSelectPicklistSerializer.java

示例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);
  }
}
 
開發者ID:apache,項目名稱:apex-core,代碼行數:15,代碼來源:AppPackage.java


注:本文中的org.codehaus.jackson.JsonGenerator.writeString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。