Skip to content

GenericMessage types cannot be encoded to XML (illegal characters)  #20

Description

@kbalthaser

If you attempt to use the DefaultXmlParser to encode a Message which is a GenericMessage, it will fail with a org.w3c.dom.DOMException.

This is due to the presence of a $ within the ClassName of an instantiated GenericMessage. Ex: GenericMessage$V23.

Sample Test:

/**
     * <p>
     *     Attempt to parse a {@link ca.uhn.hl7v2.model.GenericMessage}.  These objects have `$` in their class name, ex: `GenericMessage$V21`.
     *     The {@link DefaultXMLParser} will attempt to use the class name when constructing the {@link Document} when encoding.  The `$` is
     *     not a valid character within an element name.
     * </p>
     * <p>
     *     Construct a {@link GenericMessage} for each available version, and call {@link DefaultXMLParser#encode(Message)} on the message.
     *     We expect that a valid {@link Document} is returned, as the `$` is stripped out.
     * </p>
     */
	@Test
    public void test_encode_GenericMessage() throws Exception {

	    DefaultXMLParser xmlParser = new DefaultXMLParser();

        for (Version version : Version.values()) {

            Class<? extends Message> c = GenericMessage.getGenericMessageClass(version.getVersion());
            Message m = c.getConstructor(ModelClassFactory.class).newInstance(new GenericModelClassFactory());

            Document d = xmlParser.encodeDocument(m);
            Assert.assertNotNull(d);
            Assert.assertEquals("GenericMessage" + version.name(), d.getDocumentElement().getTagName());
        }
    }

Will be submitting a PR with a workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions