package uk.gov.register.views.representations;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import uk.gov.register.views.CsvRepresentationView;

import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

@Provider
@Produces(ExtraMediaType.TEXT_CSV)
public class CsvWriter extends RepresentationWriter<CsvRepresentationView> {
    private final CsvMapper objectMapper;

    public CsvWriter() {
        objectMapper = new CsvMapper();
    }

    @Override
    public void writeTo(CsvRepresentationView view, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
        CsvRepresentation csvRepresentation = view.csvRepresentation();

        objectMapper.writerFor(csvRepresentation.contentType)
                .with(JsonGenerator.Feature.IGNORE_UNKNOWN)
                .with(csvRepresentation.csvSchema.withLineSeparator("\r\n").withHeader())
                .writeValue(entityStream, csvRepresentation.contents);
    }
}

@@ -45,57 +45,8 @@
 s;%0A%0A
-import com.fasterxml.jackson.core.JsonGenerator;%0A
 impo
@@ -1098,68 +1098,8 @@
 pe)%0A
-                .with(JsonGenerator.Feature.IGNORE_UNKNOWN)%0A
     

Revert change to CsvWriter that specified IGNORE_UNKNOWN JsonGenerator feature