All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adgear.anoa.write.CollectionWriter Maven / Gradle / Ivy

package com.adgear.anoa.write;

import com.fasterxml.jackson.core.JsonGenerator;

import java.io.IOException;
import java.util.Collection;

class CollectionWriter extends AbstractWriter> {

  final AbstractWriter elementWriter;

  CollectionWriter(AbstractWriter elementWriter) {
    this.elementWriter = elementWriter;
  }

  @Override
  protected void write(Collection array, JsonGenerator jacksonGenerator)
      throws IOException {
    jacksonGenerator.writeStartArray(array.size());
    for (E element : array) {
      if (element == null) {
        jacksonGenerator.writeNull();
      } else {
        elementWriter.write(element, jacksonGenerator);
      }
    }
    jacksonGenerator.writeEndArray();
  }

  @Override
  void writeStrict(Collection array, JsonGenerator jacksonGenerator) throws IOException {
    jacksonGenerator.writeStartArray(array.size());
    for (E element : array) {
      if (element == null) {
        jacksonGenerator.writeNull();
      } else {
        elementWriter.writeStrict(element, jacksonGenerator);
      }
    }
    jacksonGenerator.writeEndArray();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy