Skip to content

Commit

Permalink
Merge branch '2.18' into 2.19
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 25, 2024
2 parents d4b6ad1 + 0a7cf7b commit 44dffb2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Project: jackson-dataformat-xml

#678: XML module not registered correctly when setting a custom `SerializerFactory`
(reported by @SimonCockx)
#682: `MismatchedInputException` encountered while deserializing XML to an Enum type
using a factory method
(reported by @WannabeSoftwareEngineer)

2.18.1 (28-Oct-2024)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.fasterxml.jackson.dataformat.xml.deser;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import com.fasterxml.jackson.dataformat.xml.*;

public class EnumDeserTest extends XmlTestBase
Expand All @@ -14,6 +17,29 @@ public EnumBean() { }
public EnumBean(TestEnum v) { value = v; }
}

// [dataformat-xml#682]
static enum Country682 {
ITALY("Italy"),
NETHERLANDS("Netherlands");

@JsonValue
final String value;

Country682(String value) {
this.value = value;
}

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static Country682 fromValue(String value) {
for (Country682 b : Country682.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}
}

/*
/**********************************************************
/* Unit tests
Expand All @@ -38,4 +64,12 @@ public void testRootEnum() throws Exception
assertNotNull(result);
assertEquals(TestEnum.B, result);
}

// [dataformat-xml#682]
public void testEnumDeser682() throws Exception {
String xml = MAPPER.writeValueAsString(Country682.ITALY);
assertEquals("<Country682>Italy</Country682>", xml);

assertEquals(Country682.ITALY, MAPPER.readValue(xml, Country682.class));
}
}

0 comments on commit 44dffb2

Please sign in to comment.