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

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

Go to download

Core classes for Anoa library, which aims to be a safe, convenient and fast record de/serialization wrapper for the Avro, Thrift and Jackson libraries, using the functional idioms of Java 8. The anoa-core module tries to keep upstream dependencies to a minimum.

There is a newer version: 3.1.2
Show newest version
package com.adgear.anoa.write;

import com.fasterxml.jackson.core.JsonGenerator;

import java.io.IOException;
import java.util.Map;

class MapWriter extends AbstractWriter> {

  final AbstractWriter valueElementWriter;

  MapWriter(AbstractWriter valueElementWriter) {
    this.valueElementWriter = valueElementWriter;
  }

  @Override
  protected void writeChecked(Map map, JsonGenerator jacksonGenerator) throws IOException {
    jacksonGenerator.writeStartObject();
    for (Map.Entry entry : map.entrySet()) {
      jacksonGenerator.writeFieldName(entry.getKey().toString());
      if (entry.getValue() == null) {
        jacksonGenerator.writeNull();
      } else {
        valueElementWriter.writeChecked(entry.getValue(), jacksonGenerator);
      }
    }
    jacksonGenerator.writeEndObject();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy