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

com.github.valdr.serializer.MinimalMapSerializer Maven / Gradle / Ivy

package com.github.valdr.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.github.valdr.MinimalMap;

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

/**
 * Serializes an {@link com.github.valdr.MinimalMap} like any other JSON map. All values are serialized by iterating
 * over the entry set.
 *
 * @param  map value type
 */
public class MinimalMapSerializer extends JsonSerializer> {
  @Override
  public void serialize(MinimalMap attributes, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
    throws IOException {
    jsonGenerator.writeStartObject();
    for (Map.Entry stringObjectEntry : attributes.entrySet()) {
      jsonGenerator.writeObjectField(stringObjectEntry.getKey(), stringObjectEntry.getValue());
    }
    jsonGenerator.writeEndObject();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy