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

com.codepoetics.octarine.json.serialisation.MapSerialiser Maven / Gradle / Ivy

There is a newer version: 0.18
Show newest version
package com.codepoetics.octarine.json.serialisation;

import com.fasterxml.jackson.core.JsonGenerator;

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

public final class MapSerialiser implements SafeSerialiser> {

    public static  MapSerialiser writingValuesWith(Serialiser valueSerialiser) {
        return new MapSerialiser<>(valueSerialiser);
    }

    private final Serialiser valueSerialiser;

    private MapSerialiser(Serialiser valueSerialiser) {
        this.valueSerialiser = valueSerialiser;
    }

    @Override
    public void unsafeAccept(JsonGenerator j, Map ts) throws IOException {
        j.writeStartObject();
        SafeSerialiser> entrySafeSerialiser = (j2, e) -> {
            j2.writeFieldName(e.getKey());
            valueSerialiser.accept(j2, e.getValue());
        };
        ts.entrySet().forEach(e -> {
            entrySafeSerialiser.accept(j, e);
        });
        j.writeEndObject();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy