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

Is it possible to completely ignore namespaces during deserialization? #170

Open
lamba92 opened this issue Jul 13, 2023 · 2 comments
Open

Comments

@lamba92
Copy link

lamba92 commented Jul 13, 2023

I have my data class that has:

@Serializable
@XmlSerialName(
    value = "project",
    namespace = POM_XML_NAMESPACE,
)
data class ProjectObjectModel(...)

But, some very old pom.xml do not provide any namespace at all! For example ch.qos.logback:logback-parent:0.9.7 starts with:

<?xml version="1.0"?><project>
  <parent>
    <artifactId>logback-parent</artifactId>
    <groupId>ch.qos.logback</groupId>
    <version>0.9.7</version>
  </parent>
  ...

Nowadays it is not really needed to add all this metadata since the classes themselves in which one is deserializing are the specifications! It either fits them or not.

Would it be possible to ignore errors like this one?

@pdvrieze
Copy link
Owner

At the moment there is no built-in standard way to handle missing namespaces. You could do it in the policy, but it is probably easier to have a wrapper around XmlReader that replaces the default (empty) namespace with the POM namespace for tags (but not attributes as the attributes are not qualified).

@lamba92
Copy link
Author

lamba92 commented Jul 20, 2023

Could you please show an example of both cases? Or at least a snippet to try to understand in which direction to go

artemmukhin added a commit to JetBrains/package-search-api-models that referenced this issue Jul 24, 2023
XmlUtil is strict when matching namespaces, but some very old pom.xml files do not provide any namespace. This commit introduces a wrapper around `XmlReader` to handle POM files without namespaces. Now `XML.decodePomFromString(String)` should be used instead of `XML.decodeFromString<ProjectObjectModel>(String)`.

More information: pdvrieze/xmlutil#170
artemmukhin added a commit to JetBrains/package-search-api-models that referenced this issue Jul 24, 2023
XmlUtil is strict when matching namespaces, but some very old pom.xml files do not provide any namespace. This commit introduces a wrapper around `XmlReader` to handle POM files without namespaces. Now `XML.decodePomFromString(String)` should be used instead of `XML.decodeFromString<ProjectObjectModel>(String)`.

More information: pdvrieze/xmlutil#170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants