io.sphere.sdk.attributes.Attribute Maven / Gradle / Ivy
package io.sphere.sdk.attributes;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.sphere.sdk.utils.JsonUtils;
@JsonDeserialize(as = AttributeImpl.class)
public interface Attribute {
String getName();
T getValue(AttributeMapper mapper);
public static Attribute of(final String name, final JsonNode jsonNode) {
return new AttributeImpl(name, jsonNode);
}
public static Attribute of(final String name, final Object value) {
final JsonNode jsonNode = JsonUtils.newObjectMapper().valueToTree(value);
return of(name, jsonNode);
}
public static Attribute of(final AttributeSetter setter, final T value) {
final JsonNode jsonNode = setter.getMapper().serialize(value);
return of(setter.getName(), jsonNode);
}
//todo add example with optional as result to not separate result and guard
default AttributeExtraction collect(AttributeDefinition attrDefinition) {
return AttributeExtraction.of(attrDefinition, this);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy