Adds a value to a writer if value is not <code>null</code>.

@param writer
writer to add object to.
@param field
field name to set.
@param value
field value.
@throws JSONException
if io error occurs.
909
public static void addIfNotNull(JSONWriter writer, String field,
			Boolean value) throws JSONException {
		if (value == null)
			return;
		writer.key(field);
		writer.value(value);
	}
883439
public final void writeNumberField(String fieldName, int value)
        throws IOException, JsonGenerationException
    {
        writeFieldName(fieldName);
        writeNumber(value);
    }
1270186
public static final void setWriter(String format, TreeWriter writer) {
		String key = format.toLowerCase();
		writers.put(key, writer);
		if (JSON.equals(key)) {
			cachedJsonWriter = writer;
		}
	}
456249
public void set(String fieldName, Object value) throws IOException {
    getValueMarshaller(fieldName).setWritableObject(struct, value);
    LOG.debug("Set {}={}", fieldName, value);
  }
117249
private void writeDateField(String fieldName, Object value) throws IOException
   {
      if (value instanceof String)
      {
         m_writer.writeNameValuePair(fieldName + "_text", (String) value);
      }
      else
      {
         Date val = (Date) value;
         m_writer.writeNameValuePair(fieldName, val);
      }
   }
480608
public void writeStringField(String fieldName, String value)
        throws IOException, JsonGenerationException
    {
        writeFieldName(fieldName);
        writeString(value);
    }
1142357
public void add(String name, JsonBuffer value) {
		if (value != null && value != this && !value.isEmpty()) {
			this.content.put(name, value);
		}
	}
834653
public JSONWriter valueString(String value) throws IOException {
        beforeValue();

        writer.write(JSON.QUOTE);
        writer.write(escape(value));
        writer.write(JSON.QUOTE);
        return this;
    }
385583
@SuppressWarnings("unchecked")
	public void addWriter(RecordWriter<Record> writer)
	{
		// avoid using the array-list here to reduce one level of object indirection
		if (this.writers == null) {
			this.writers = new RecordWriter[] {writer};
		}
		else {
			RecordWriter<Record>[] ws = new RecordWriter[this.writers.length + 1];
			System.arraycopy(this.writers, 0, ws, 0, this.writers.length);
			ws[this.writers.length] = writer;
			this.writers = ws;
		}
	}
567355
public void writeValue(Object value) throws IOException
    {
        if (value == null) {
            writeNullValue();
            return;
        }
        _writeValue(value, _writerLocator.findSerializationType(value.getClass()));
    }
815692
public JsonWriter value(String value) throws IOException {
        if (value == null) {
            return nullValue();
        }
        beforeValue(false);
        string(value);
        return this;
    }
1317325
public JsonWriter value(double value) {
        startValue();

        final long i = (long) value;
        if (value == (double) i) {
            writer.print(i);
        } else {
            writer.print(value);
        }
        return this;
    }
183944
public static <T> void addIfNotNull(JSONWriter writer, String field,
			T value, JsonObjectWriter<T> objWriter) throws JSONException {
		if (value == null)
			return;
		writer.key(field);
		writer.object();
		objWriter.write(writer, value);
		writer.endObject();
	}
896958
@Override
  public void write(JsonWriterImpl out, T value)
  {
    if (value == null) {
      out.writeNull();
    }
    else if (value.getClass() != Object.class) {
      out.writeObjectValue(value);
    }
  }
944261
public static String serialize(Value value) throws JSONException {
		StringWriter writer = new StringWriter();
		Serializer.serialize(value, writer);
		return writer.toString();
	}
707832
public static void put(Writer writer, Enum<?> value) throws IOException {
		if (value == null) {
			writer.write("null");
		} else {
			writer.write("\"");
			writer.write(sanitize(value.name()));
			writer.write("\"");
		}
	}
573856
private void appendValue(String string) throws JSONException {
        assert string != null;
        if (m_mode == 'k' || m_mode == 'i' || m_mode == 'd') {
            throw new JSONException("Value out of sequence.");
        }
        try {
            if (m_mode == 'a') {
                if (m_expectingComma) {
                    m_writer.write(',');
                }
            }
            else if (m_mode == 'o') {
                m_mode = 'k';
            }
            m_writer.write(string);
        }
        catch (IOException e) {
            throw new JSONException(e);
        }
        m_expectingComma = true;
    }