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

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

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

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.sphere.sdk.models.Base;
import io.sphere.sdk.client.JsonParseException;

import static java.lang.String.format;

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 AttributeMapper mapper) {
        try {
            return mapper.deserialize(value);
        } catch (final JsonParseException e) {
            throw new JsonParseException(format("Cannot parse attribute %s with mapper %s.", getName(), mapper), e.getCause());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy