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

Empty root tag into List deserialization bug #319

Closed
Seatec13 opened this issue Oct 25, 2018 · 7 comments
Closed

Empty root tag into List deserialization bug #319

Seatec13 opened this issue Oct 25, 2018 · 7 comments

Comments

@Seatec13
Copy link

Seatec13 commented Oct 25, 2018

/*copied from FasterXML/jackson-databind#2163 */

Hello,
I have a strange problem with jackson-dataformat 2.9.* (with 2.8.* everything work good):

Data class: (Lombok -- modify for test)

@Data
public class PackInstanceOrder {
    private Long orderId;
    private Long orderTypeId;
}

Simple test (Kotlin?):

    @Test
    fun test() {
        val XML_OBJECT_MAPPER = XmlMapper()

        val xml = "<orders></orders>"Labels
        val orders: List<PackInstanceOrder> = XML_OBJECT_MAPPER.readValue(xml,
            XML_OBJECT_MAPPER.getTypeFactory().constructCollectionType(List::class.java, PackInstanceOrder::class.java))

        assertThat(orders, notNullValue())
    }

throw an error:

    com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "" (class PackInstanceOrder), not marked as ignorable (2 known properties: "orderId", "orderTypeId"])
    at [Source: (StringReader); line: 1, column: 18] (through reference chain: java.util.ArrayList[0]->PackInstanceOrder[""])

When adding @JsonIgnoreProperties(ignoreUnknown = true) annotation to PackInstanceOrder, error was changed:

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected end-of-input when binding data into PackInstanceOrder
    at [Source: (StringReader); line: 1, column: 18] (through reference chain: java.util.ArrayList[1])

BUT! When I change xml to

<orders/>

test didn't throw any errors and pass well.

@cowtowncoder
Copy link
Member

Yes, can reproduce this; adding a (failing) unit test.

@cowtowncoder
Copy link
Member

For some reason, seems to work for master. Possibly fixed. But that's just for 3.0 (long ways still); problem reproducible with 2.10.

@Reamer
Copy link

Reamer commented Oct 22, 2019

Is there any plan to back port a potential fix?

@cowtowncoder cowtowncoder added 2.11 and removed 2.10 labels Oct 22, 2019
@cowtowncoder
Copy link
Member

@Reamer if someone can figure out how, sure. Likely would go in 2.11, unless it's a trivial change (in which could go in 2.10.x patch). I don't think active work is going on for this so help would be appreciated.

@Reamer
Copy link

Reamer commented Oct 23, 2019

Hi @cowtowncoder,
Sorry, I have no deep knowledge in jackson and it's components to provide any help. I can provide dependency-check-sonar-plugin as an example project, maybe that's helpful.

@cowtowncoder
Copy link
Member

@Reamer no problem, and thank you for the offer: we do have a failing (in 2.x) test already, so that's fine. Only need to have time to dig in, hope to find solution for 2.x (and maybe understand what changes to 3.0 are relevant).

@cowtowncoder
Copy link
Member

Have not been able to fix, but I have bit better idea on what is going on, and hope to fix this for 2.11. Challenge is that of coercing empty XML String into "empty" value of POJO, Map or List, as a special case, being accepted as empty/null when not being bound to String (or scalar)

@cowtowncoder cowtowncoder added 2.12 and removed 2.11 labels Jun 5, 2020
@cowtowncoder cowtowncoder changed the title Empty root tag deserialization bug Empty root tag into List deserialization bug Jun 5, 2020
alex-bel-apica pushed a commit to ApicaSystem/jackson-dataformat-xml that referenced this issue Sep 4, 2020
# Conflicts:
#	release-notes/VERSION-2.x
#	src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser319Test.java
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

3 participants