You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is it possible to completely ignore namespaces during deserialization? #170
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?
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).
I'm not sure why the workaround doesn't work, what happens if you use a DelegatingXmlReader explicitly? The other way that you can work around it is to use the policy to do recovery (rather than throw an exception) – the filter you have should be more resilient.
The problem seems to be here. When reader.name is invoked, somehow the QName generated does not use the overridden namespaceURI.
Overriding the name as well works again:
public inline fun <reified T : Any> XML.decodeFromString(
namespace: String,
string: String,
): T {
return decodeFromReader<T>(ManualNamespaceXmlReader(namespace, string))
}
public class ManualNamespaceXmlReader(
override val namespaceURI: String,
xmlString: String,
) : XmlReader by xmlStreaming.newReader(xmlString) {
override fun toString(): String = "ManualNamespaceXmlReader(namespaceURI=\"$namespaceURI\")"
override val name: QName
get() = QName(namespaceURI, localName, prefix)
}
@lamba92 The problem is that when using delegation the reader.name will call the namespaceURI in the delegate, rather than the overridden writer. Where if you manually delegate (not using by delegate) the implementation of name would have to either be explicitly overridden, or it will use the default implementation (that gets the components directly).
Activity
pdvrieze commentedon Jul 19, 2023
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
XmlReaderthat replaces the default (empty) namespace with the POM namespace for tags (but not attributes as the attributes are not qualified).lamba92 commentedon 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
Fix parsing of POM files without namespaces
Fix parsing of POM files without namespaces
lamba92 commentedon Aug 8, 2024
Hi, any updates on this? Since v83.3 this workaround:
is not working anymore. Is there now a way to properly ignore namespaces during deserialization?
pdvrieze commentedon Aug 8, 2024
I'm not sure why the workaround doesn't work, what happens if you use a DelegatingXmlReader explicitly? The other way that you can work around it is to use the policy to do recovery (rather than throw an exception) – the filter you have should be more resilient.
lamba92 commentedon Aug 20, 2024
The problem seems to be here. When
reader.nameis invoked, somehow theQNamegenerated does not use the overriddennamespaceURI.Overriding the
nameas well works again:pdvrieze commentedon Aug 21, 2024
@lamba92 The problem is that when using delegation the
reader.namewill call thenamespaceURIin the delegate, rather than the overridden writer. Where if you manually delegate (not usingby delegate) the implementation ofnamewould have to either be explicitly overridden, or it will use the default implementation (that gets the components directly).