package de.champonthis.buntspecht.controller.model;

import java.io.IOException;

import org.springframework.boot.jackson.JsonComponent;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.querydsl.core.Tuple;

@JsonComponent
public class TupleSerializer extends JsonSerializer<Tuple> {

    @Override
    public void serialize(Tuple value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value.toArray().length > 1) {
            gen.writeStartArray();
        }
        for (Object object : value.toArray()) {
            gen.writeObject(object);
        }
        if (value.toArray().length > 1) {
            gen.writeEndArray();
        }
    }

}