当前位置: 首页>>代码示例>>Java>>正文


Java JsonGenerator.writeNull方法代码示例

本文整理汇总了Java中org.codehaus.jackson.JsonGenerator.writeNull方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.writeNull方法的具体用法?Java JsonGenerator.writeNull怎么用?Java JsonGenerator.writeNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.jackson.JsonGenerator的用法示例。


在下文中一共展示了JsonGenerator.writeNull方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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:rhli,项目名称:hadoop-EAR,代码行数:41,代码来源:JMXJsonServlet.java

示例7: serialize

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Short s, JsonGenerator jGen,
                      SerializerProvider serializer) throws IOException,
                                              JsonProcessingException {
    if (s == null) jGen.writeNull();
    else jGen.writeNumber(s.shortValue() & 0xffff);
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:8,代码来源:UShortSerializer.java

示例8: generateEntry

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void generateEntry(JsonGenerator generator,
        Map.Entry<String, Object> x) throws IOException,
        JsonGenerationException, JsonProcessingException {
    if (x.getValue() == null) {
        if (!filterOutNullValue) {
            generator.writeFieldName(x.getKey());
            generator.writeNull();
        }
        return;
    }

    generator.writeFieldName(x.getKey());
    if (Map.class.isAssignableFrom(x.getValue().getClass())) {
        encodeMap((Map<String, Object>) x.getValue(), generator);
    } else if (x.getValue().getClass().isArray()) {
        generator.writeStartArray();
        int length = Array.getLength(x.getValue());
        for (int i = 0; i < length; i++) {
            generator.writeObject(Array.get(x.getValue(), i));    
        }
        generator.writeEndArray();
    } else if (x.getValue() instanceof Collection) {
        generator.writeStartArray();
        Iterator iterator = ((Collection) (x.getValue())).iterator();
        while (iterator.hasNext()) {
            generator.writeObject(iterator.next());    
        }
        generator.writeEndArray();
    } else {
        generator.writeObject(x.getValue());
    }
}
 
开发者ID:pulsarIO,项目名称:jetstream,代码行数:34,代码来源:JSONMessageSerializer.java

示例9: serialize

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
public void serialize(String object, JsonGenerator jGen, SerializerProvider sProvider) 
throws IOException, JsonProcessingException {
  jGen.writeNull();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:5,代码来源:BlockingSerializer.java

示例10: writeObject

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
private static void writeObject(final JsonGenerator jg, final boolean description, 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, description, 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, null, cds.get(key));
      }
      jg.writeEndObject();
    } else if(value instanceof TabularData) {
      TabularData tds = (TabularData)value;
      jg.writeStartArray();
      for(Object entry : tds.values()) {
        writeObject(jg, description, entry);
      }
      jg.writeEndArray();
    } else {
      jg.writeString(value.toString());
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:42,代码来源:JSONBean.java

示例11: writeValue

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/** Called to write value.*/
protected void writeValue(Schema fieldSchema, Object datum, JsonGenerator generator) throws IOException {
    try {
        switch (fieldSchema.getType()) {
            case INT:
                generator.writeNumber(((Number) datum).intValue());
                break;
            case LONG:
                generator.writeNumber((Long) datum);
                break;
            case DOUBLE:
                generator.writeNumber((Double) datum);
                break;
            case BOOLEAN:
                generator.writeBoolean((Boolean) datum);
                break;
            case STRING:
                generator.writeString(datum.toString());
                break;
            case BYTES:
                writeBytes(datum, generator);
                break;
            case NULL:
                generator.writeNull();
                break;
            case RECORD:
                writeRecord((RecordSchema) fieldSchema, datum, generator);
                break;
            case ENUM:
                writeEnum((EnumSchema) fieldSchema, (Enum) datum, generator);
                break;
            case ARRAY:
                writeArray((ArraySchema) fieldSchema, (List) datum, generator);
                break;
            case MAP:
                writeMap((MapSchema) fieldSchema, (Map) datum, generator);
                break;
            case UNION:
                writeUnion((UnionSchema) fieldSchema, datum, generator);
                break;
            default:
                error(fieldSchema, datum);
        }
    } catch (NullPointerException e) {
        throw npe(e, " of "+ fieldSchema.getName());
    }
}
 
开发者ID:archcentric,项目名称:BaijiSerializer4J,代码行数:48,代码来源:SpecificJsonWriter.java


注:本文中的org.codehaus.jackson.JsonGenerator.writeNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。