InvalidMembers Description
As explained previously, the ContentFailure holds a list : List<ModddelInvalidMember> invalidMembers
, where ModddelInvalidMember
is a wrapper class that holds an invalid modddel and its description. This description is used in the toString
method of the ContentFailure. It varies depending on the entity kind.
For IterableEntity
The description is by default "item $index"
, except for the MappedKeys/MappedValues kinds where it's "entry $index"
.
As we know already, the collection of an IterableEntity can be converted to an iterable. The index
that we talk about here is the index of a modddel in that iterable.
You can customize the description for any IterableEntity by overriding the $description
method.
For example : Let's say we have a BookList
ListEntity that holds a list of books.
You can also optionally override the $descriptionDetails
method. This method has two parameters : the modddel
that is held inside the collection and its index. It returns a string that will be appended to the description, in parenthesis.
In our example :
You can cast the modddel
to whatever type the modddel held inside the collection is.
For example : If you have a ListEntity
that holds a list of Book
, you can safely cast modddel
like so :
If you have a ListEntity
that is a union of modddels where one case-modddel holds a list of Book
, and the other case-modddel holds a list of Article
, you can do :
For Iterable2Entity
The collection of an Iterable2Entity can be converted to two iterables of modddels. Therefore, there are two descriptions, one for each iterable.
By default :
The description of the modddels of the first iterable is
"first $index"
, except for the Map kinds (MapEntity...) where it's"key $index"
.The description of the modddels of the second iterable is
"second $index"
, except for the Map kinds (MapEntity...) where it's"value $index"
.
You can customize these descriptions by overriding respectively the $description1
and $description2
methods.
You can also optionally override the $descriptionDetails1
and $descriptionDetails2
methods.