Search in sources :

Example 1 with UNABLE_TO_SERIALIZE_TO_JSON

use of org.talend.dataprep.exception.error.CommonErrorCodes.UNABLE_TO_SERIALIZE_TO_JSON in project data-prep by Talend.

the class CSVFormatUtils method compileParameterProperties.

/**
 * Retrieve properties associated with a dataset content and put them in a
 * map with their corresponding key.
 *
 * @param separator the specified separator
 * @param updatedParameters the updated header
 */
Map<String, String> compileParameterProperties(Separator separator, Map<String, String> updatedParameters) {
    List<String> header = separator.getHeaders().stream().map(p -> p.getKey()).collect(Collectors.toList());
    // header
    String jsonHeader;
    try {
        jsonHeader = mapper.writeValueAsString(header);
    } catch (Exception e) {
        throw new TDPException(UNABLE_TO_SERIALIZE_TO_JSON, e);
    }
    updatedParameters.put(HEADER_COLUMNS_PARAMETER, jsonHeader);
    // separator
    updatedParameters.put(SEPARATOR_PARAMETER, String.valueOf(separator.getSeparator()));
    // if no parameter set set take the default one
    updatedParameters.putIfAbsent(TEXT_ENCLOSURE_CHAR, defaultTextEnclosure);
    updatedParameters.putIfAbsent(ESCAPE_CHAR, defaultEscapeChar);
    return updatedParameters;
}
Also used : Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) Component(org.springframework.stereotype.Component) TDPException(org.talend.dataprep.exception.TDPException) UNABLE_TO_SERIALIZE_TO_JSON(org.talend.dataprep.exception.error.CommonErrorCodes.UNABLE_TO_SERIALIZE_TO_JSON) Map(java.util.Map) CSVFormatFamily(org.talend.dataprep.schema.csv.CSVFormatFamily) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) TDPException(org.talend.dataprep.exception.TDPException) TDPException(org.talend.dataprep.exception.TDPException)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Value (org.springframework.beans.factory.annotation.Value)1 Component (org.springframework.stereotype.Component)1 TDPException (org.talend.dataprep.exception.TDPException)1 UNABLE_TO_SERIALIZE_TO_JSON (org.talend.dataprep.exception.error.CommonErrorCodes.UNABLE_TO_SERIALIZE_TO_JSON)1 CSVFormatFamily (org.talend.dataprep.schema.csv.CSVFormatFamily)1