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

io.sphere.sdk.attributes.NestedSetAttributeMapperImpl Maven / Gradle / Ivy

The newest version!
package io.sphere.sdk.attributes;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import io.sphere.sdk.json.JsonException;
import io.sphere.sdk.products.AttributeContainer;

import java.io.IOException;
import java.util.List;
import java.util.Set;

import static java.util.stream.Collectors.toSet;

class NestedSetAttributeMapperImpl extends AttributeMapperImpl> {
    NestedSetAttributeMapperImpl() {
        super(new TypeReference>() {});
    }

    @Override
    public Set deserialize(JsonNode value) {
        try {
            final Set> raw = mapper().reader(new TypeReference>>() {}).readValue(value);

            return raw.stream().map(AttributeContainer::of).collect(toSet());
        } catch (final IOException e) {
            throw new JsonException(e);
        }
    }

    @Override
    public JsonNode serialize(final Set attributeContainer) {
        return mapper().valueToTree(attributeContainer.stream().map(AttributeContainer::getAttributes).collect(toSet()));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy