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

io.sphere.sdk.products.attributes.AttributeMapperImpl Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.products.attributes;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.sphere.sdk.json.JsonException;
import io.sphere.sdk.models.Base;
import io.sphere.sdk.json.SphereJsonUtils;

import java.io.IOException;

class AttributeMapperImpl extends Base implements AttributeMapper {
    private static final ObjectMapper mapper = SphereJsonUtils.newObjectMapper();
    private final TypeReference typeReference;

    AttributeMapperImpl(final TypeReference typeReference) {
        this.typeReference = typeReference;
    }

    @Override
    public T deserialize(final JsonNode value) {
        try {
            return  mapper.readerFor(typeReference).readValue(value);
        } catch (final IOException e) {
            throw new JsonException(e);
        }
    }

    @Override
    public JsonNode serialize(final T value) {
        return mapper.valueToTree(value);
    }

    protected final ObjectMapper mapper() {
        return mapper;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy