这是indexloc提供的服务,不要输入任何密码
Skip to content

Empty root tag into List deserialization bug #319

@Seatec13

Description

@Seatec13

/*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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions