io.sphere.sdk.attributes.AttributeImpl Maven / Gradle / Ivy
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());
}
}
}