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

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

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 write(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.write(entry.getValue(), jacksonGenerator);
      }
    }
    jacksonGenerator.writeEndObject();
  }

  @Override
  void writeStrict(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.writeStrict(entry.getValue(), jacksonGenerator);
      }
    }
    jacksonGenerator.writeEndObject();  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy