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

io.quarkus.hal.HalCollectionWrapperJsonbSerializer Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package io.quarkus.hal;

import javax.json.bind.serializer.JsonbSerializer;
import javax.json.bind.serializer.SerializationContext;
import javax.json.stream.JsonGenerator;

public class HalCollectionWrapperJsonbSerializer implements JsonbSerializer {

    @Override
    public void serialize(HalCollectionWrapper wrapper, JsonGenerator generator, SerializationContext context) {
        generator.writeStartObject();
        writeEmbedded(wrapper, generator, context);
        writeLinks(wrapper, generator, context);
        generator.writeEnd();
    }

    private void writeEmbedded(HalCollectionWrapper wrapper, JsonGenerator generator, SerializationContext context) {
        generator.writeKey("_embedded");
        generator.writeStartObject();
        generator.writeKey(wrapper.getCollectionName());
        generator.writeStartArray();
        for (HalEntityWrapper entity : wrapper.getCollection()) {
            context.serialize(entity, generator);
        }
        generator.writeEnd();
        generator.writeEnd();
    }

    private void writeLinks(HalCollectionWrapper wrapper, JsonGenerator generator, SerializationContext context) {
        context.serialize("_links", wrapper.getLinks(), generator);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy