当前位置: 首页>>代码示例>>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;未经允许,请勿转载。