Closed pintomau closed 2 years ago
No and yes :)
No atm there is no helper method for getting a specific attribute as a specific type as like as in the v1.
Yes there are possibilities to do so. The Attributes are already correctly deserialized only the return type is Object as this is the least common denominator for an attribute value. We added an AttributeAccessor which can help accessing the attributes e.g. by name. See
This accessor comes also with some other small helpers methods.
We may introduce also an accessor which allows to retrieve a specific attribute by name and type. But atm you would have to build such an accessor by yourself.
Btw every model comes with an with<Model>
method to apply an accessor, so this could also be done on the attribute level e.g.:
Map<String, Attribute> attributes = variant.withProductVariant(AttributeAccessor::asMap);
attributes.get("text").withAttribute(attribute -> (String)attribute.getValue());
attributes.get("ltext").withAttribute(attribute -> (LocalizedString)attribute.getValue());
I added now the other accessor methods to get type safe values
Here you can see how to use them:
Will be available with the next release
Alright, I see, interesting. Thanks for the additions.
Hi!
SDK1 had the feature of getting a typed attribute via the
attribute.getValueAsX
.SDK2 seems to return an Object type value only.
Is there, within SDK2, a way to get the attribute in the concrete deserialized type? Or would this be a new feature within SDK2?
Thanks.