0

Apache-cxf, trying to unmarshal xml, that has some namespaces, so @XmlRootElement contains name and namespace attrs.

The question is: How to make this test work?

    @XmlRootElement(name = "MyClass", namespace = "http://foo_url")
    class MyClass {
      @XmlElement(name = "version")
      var version: String = _
    }
    class SimpleTest {
      @Test
      def test(): Unit = {

        // given
        val xmlString =
          """<MyClass xmlns="http://foo_url"> <version>10</version></MyClass> """

        val xmlSource = new XMLSource(new ByteArrayInputStream(xmlString.getBytes("UTF-8")))

        // when
        val node: MyClass = xmlSource.getNode(
          "MyClass",
          Collections.singletonMap(
            "ns1",
            "http://foo_url"
          ),
          classOf[MyClass])

        // then
        assertThat(node, is( not( nullValue() ) )) //null
        assertThat(node.version, is("10")) /// null !
      }

I guess it is all about namespacing? Basically I want to leave XmlRootElement as it is now.

ses
  • 13,174
  • 31
  • 123
  • 226

1 Answers1

0

Fixed that issue by adding namespacefor version in @XmlElement.

 @XmlElement(name = "version", namespace = "http://foo_url")
 var version: String = _

The thing is that in previous version of cxf it worked without specifying that namespance.

(I hate annotations)

related question: here

Community
  • 1
  • 1
ses
  • 13,174
  • 31
  • 123
  • 226