Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated element types are ignored by default if kotlin property is not a list. #145

Closed
mgroth0 opened this issue May 18, 2023 · 2 comments
Labels
indev The issue is fixed/implemented in the dev branch

Comments

@mgroth0
Copy link

mgroth0 commented May 18, 2023

If I am deserializing an XML file that has repeated element types, I can set the kotlin property to either be a single instance or a list.

In kotlin, I can use:

@Serializable
@XmlSerialName("Track", NAMESPACE_VSTD, PREFIX_VSTD)
class Track(
    val frameAnnotations: FrameAnnotation
)

or

@Serializable
@XmlSerialName("Track", NAMESPACE_VSTD, PREFIX_VSTD)
class Track(
    val frameAnnotations: List<FrameAnnotation>
)

Both of the above serializable classes can be used to deserialize the XML file without any error being thrown. However, the first one silently ignores the repeated elements. This is an issue when I need to make sure I am not ignoring any data.

The default configuration throws exceptions if an element in the XML is not found in the serializable class. Therefore, users are made to epect that this library ensures data is not being ignored. However, in this case it is.

Is there a configuration option that can make it so errors are thrown when a repeated element is found but the property is not set as a list? And if so, perhaps this should be enabled by default.

pdvrieze added a commit that referenced this issue May 19, 2023
is not default behaviour as it is somewhat up to the serializer to deal
with duplicate values, rather than the format.
@pdvrieze pdvrieze added the indev The issue is fixed/implemented in the dev branch label May 19, 2023
@pdvrieze
Copy link
Owner

I've added an option to deal with this in dev (there is an extra function/option in the policy). In principle however it is somewhat up to the serializer to deal with duplicate values of its elements, but as presence of elements was already tracked to handle null values it was easy to implement. The new property in the policy is: throwOnRepeatedElement.

@pdvrieze
Copy link
Owner

pdvrieze commented Jul 5, 2023

Now released as 0.86.1

@pdvrieze pdvrieze closed this as completed Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
indev The issue is fixed/implemented in the dev branch
Projects
None yet
Development

No branches or pull requests

2 participants