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

io.sphere.sdk.products.attributes.AttributeImpl 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.annotation.JsonCreator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.sphere.sdk.json.JsonException;
import io.sphere.sdk.models.Base;

import static java.lang.String.format;

final class AttributeImpl extends Base implements Attribute {
    private final String name;

    @JsonSerialize
    private final JsonNode value;

    @JsonCreator
    public AttributeImpl(final String name, final JsonNode value) {
        this.name = name;
        this.value = value;
    }

    public String getName() {
        return name;
    }

    @Override
    public  T getValue(final AttributeAccess access) {
        try {
            return access.attributeMapper().deserialize(value);
        } catch (final JsonException e) {
            throw new JsonException(format("Cannot parse attribute %s with mapper %s.", getName(), access.attributeMapper()), e.getCause());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy