<commit_before>/**
 * Copyright 2017 European Union, interactive instruments GmbH
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package de.ii.ldproxy.service;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import de.ii.xsf.configstore.api.rest.GenericResourceSerializer;
import de.ii.xsf.core.api.JsonViews;
import de.ii.xsf.logging.XSFLogger;
import org.forgerock.i18n.slf4j.LocalizedLogger;

import java.io.IOException;

/**
 * @author zahnen
 */
public class LdProxyServiceSerializer extends GenericResourceSerializer<LdProxyService> {
    private static final LocalizedLogger LOGGER = XSFLogger.getLogger(LdProxyServiceSerializer.class);

    private final ObjectMapper updateJsonMapper;

    public LdProxyServiceSerializer(ObjectMapper jsonMapper) {
        super(jsonMapper);
        updateJsonMapper = new ObjectMapper();
        updateJsonMapper.enable(SerializationFeature.INDENT_OUTPUT);
        updateJsonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        updateJsonMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    }

    @Override
    public String serializeAdd(LdProxyService resource) throws IOException {
        return jsonMapper
                .writerWithView(JsonViews.FullView.class)
                .writeValueAsString(resource);
    }

    @Override
    public String serializeUpdate(LdProxyService resource) throws IOException {
        return jsonMapper
                .writerWithView(JsonViews.ConfigurationView.class)
                .without(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS)
                .writeValueAsString(resource);
    }
}

<commit_msg>empty strings in updates, fixes #91<commit_after>/**
 * Copyright 2017 European Union, interactive instruments GmbH
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package de.ii.ldproxy.service;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import de.ii.xsf.configstore.api.rest.GenericResourceSerializer;
import de.ii.xsf.core.api.JsonViews;
import de.ii.xsf.logging.XSFLogger;
import org.forgerock.i18n.slf4j.LocalizedLogger;

import java.io.IOException;

/**
 * @author zahnen
 */
public class LdProxyServiceSerializer extends GenericResourceSerializer<LdProxyService> {
    private static final LocalizedLogger LOGGER = XSFLogger.getLogger(LdProxyServiceSerializer.class);

    private final ObjectMapper updateJsonMapper;

    public LdProxyServiceSerializer(ObjectMapper jsonMapper) {
        super(jsonMapper);
        updateJsonMapper = jsonMapper.copy();
        updateJsonMapper.setSerializationInclusion(JsonInclude.Include.NON_ABSENT);
    }

    @Override
    public String serializeAdd(LdProxyService resource) throws IOException {
        return jsonMapper
                .writerWithView(JsonViews.FullView.class)
                .writeValueAsString(resource);
    }

    @Override
    public String serializeUpdate(LdProxyService resource) throws IOException {
        return updateJsonMapper
                .writerWithView(JsonViews.ConfigurationView.class)
                .without(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS)
                .writeValueAsString(resource);
    }
}


{'fraction_non_alphanumeric': 0.0793193717277487, 'fraction_numerical': 0.0062827225130890054, 'mean_word_length': 3.911311053984576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '143176', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1028, 'n_words': 226}