Skip to content

Error when try parse maven pom #270

Closed as duplicate
Closed as duplicate

Description

@morkovkin

Hello i try to parse pom file from maven by ktor (kotlinx.serialization). Im sorry if i mistake to choose project, but i really need help.

I have xml like

<metadata xmlns="http://maven.apache.org/METADATA/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/METADATA/1.1.0 https://maven.apache.org/xsd/repository-metadata-1.1.0.xsd">
   <groupId>groupId</groupId>
   <artifactId>artifactId</artifactId>
   <versioning>
      <latest>1.0.60</latest>
      <release>1.0.61</release>
      <versions>
         <version>1.0.60</version>
         <version>1.0.61</version>
      </versions>
   <lastUpdated>20250320151009</lastUpdated>
   </versioning>
</metadata>

and dao like

@Serializable
@XmlSerialName("metadata")
internal data class DaoMavenMetadata(
    @XmlElement(false)
    @XmlSerialName("modelVersion")
    val modelVersion: String? = null,
    @XmlElement(true)
    @XmlSerialName("groupId")
    var groupId: String? = null,
    @XmlElement(true)
    @XmlSerialName("artifactId")
    val artifactId: String? = null,
    @XmlElement(true)
    @XmlSerialName("versioning")
    val versioning: DaoVersioning? = null,
)

I dose not have special settings for xml in my ktor configuration. So when i try to parse i see error
Local name "{http://maven.apache.org/METADATA/1.1.0}metadata" for root tag does not match expected name "metadata"
I was try configure ktor to disable namespace check by ignoreNamespaces method and write custom policy (just use DefaultXmlSerializationPolicy builder and put unknownChildHandler inside) but it's still throw error.

I found one way just remove @XmlSerialName("metadata") from root element and it will be ok.

actually when i parse xml with root like:

<metadata modelVersion="1.1.0">

it will ok

My question is: How disable namespace check for all my items? remove XmlSerialName annotation is this the right way or not?

PS: thank you for project it's awesome
PSS: sorry about my English

Activity

  1. pdvrieze commented on Mar 21, 2025

    @pdvrieze
    Owner

    The serialization does not really support ignoring namespaces. There is one option, and that is for the root tag name to be specified (in which case you can use the just read tag name - with or without namespace). The other option is to explicitly create your XmlReader and use a filter that adjusts this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions