-
-
Notifications
You must be signed in to change notification settings - Fork 233
Add test to verify #517 still failing #673
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
86bcc89
Add tests
JooHyukKim cfc7c9c
Move to failing directory for record test
JooHyukKim 061d436
Update XmlWrapperRecord517Test.java
JooHyukKim e72f1c6
Clean up code and fix jdk 17 error
JooHyukKim d4e4ee8
fix test
JooHyukKim 18efb70
Merge branch '2.18' into test571
JooHyukKim c7bc7c1
Fix importt ordering
JooHyukKim be3bc77
Merge branch 'test571' of https://github.com/JooHyukKim/jackson-dataf…
JooHyukKim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...17/java/com/fasterxml/jackson/dataformat/xml/records/failing/XmlWrapperRecord517Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package com.fasterxml.jackson.dataformat.xml.records.failing; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
| import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
| import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| // [databind#517] XML wrapper doesn't work with java records | ||
| // Equivalent to on in jdk17/.../deser/XmlWrapperRecord517Test.java | ||
| public class XmlWrapperRecord517Test | ||
| extends XmlTestBase | ||
| { | ||
|
|
||
| public record Request( | ||
| @JacksonXmlElementWrapper(localName = "messages") | ||
| @JacksonXmlProperty(localName = "message") | ||
| List<Message> messages | ||
| ) { | ||
| public Request {} | ||
|
|
||
| private Request() {this(null);} | ||
| } | ||
|
|
||
| public record Message(String text) { | ||
| public Message { | ||
| } | ||
|
|
||
| private Message() { | ||
| this(null); | ||
| } | ||
| } | ||
|
|
||
| private final String expectedXML = | ||
| "<Request>" + | ||
| "<messages>" + | ||
| "<message>" + | ||
| "<text>Hello, World!</text>" + | ||
| "</message>" + | ||
| "</messages>" + | ||
| "</Request>"; | ||
|
|
||
| @Test | ||
| public void testWrapper() throws Exception { | ||
| XmlWrapperRecord517Test.Request request = new Request(List.of(new Message("Hello, World!"))); | ||
|
|
||
| // test serialization | ||
| String xml = newMapper().writeValueAsString(request); | ||
| assertEquals(expectedXML, xml); | ||
|
|
||
| // test deserialization | ||
| Request result = newMapper().readValue(xml, Request.class); | ||
|
|
||
| assertEquals(request.messages().size(), result.messages().size()); | ||
| assertEquals(request.messages().get(0).text(), result.messages().get(0).text()); | ||
| } | ||
| } | ||
102 changes: 102 additions & 0 deletions
102
src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XmlWrapperClass517Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package com.fasterxml.jackson.dataformat.xml.deser; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
| import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
| import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| // [databind#517] XML wrapper doesn't work with java records | ||
| // Equivalent to on in jdk17/.../records/XmlWrapperRecord517Test.java | ||
| public class XmlWrapperClass517Test | ||
| extends XmlTestBase | ||
| { | ||
| public static final class Request { | ||
| @JacksonXmlElementWrapper(localName = "messages") | ||
| @JacksonXmlProperty(localName = "message") | ||
| private final List<Message> messages; | ||
|
|
||
| private Request() { this.messages = null; } | ||
| public Request(List<Message> messages) { this.messages = messages; } | ||
|
|
||
| public List<Message> getMessages() { return messages; } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (!(o instanceof Request)) return false; | ||
| return Objects.equals(messages, ((Request)o).messages); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { return Objects.hash(messages); } | ||
|
|
||
| @Override | ||
| public String toString() { return "Request{messages=" + messages + '}'; } | ||
| } | ||
|
|
||
| public static final class Message { | ||
|
|
||
| private final String text; | ||
|
|
||
| private Message() { this.text = null; } | ||
| public Message(String text) { this.text = text; } | ||
|
|
||
| public String getText() { return text; } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (!(o instanceof Message)) return false; | ||
| Message message = (Message) o; | ||
| return Objects.equals(text, message.text); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { return Objects.hash(text); } | ||
|
|
||
| @Override | ||
| public String toString() { return "Message{text='" + text + "\'}"; } | ||
| } | ||
|
|
||
| private final ObjectMapper mapper = newMapper(); | ||
|
|
||
| private final String expectedXML = | ||
| "<Request>" + | ||
| "<messages>" + | ||
| "<message>" + | ||
| "<text>given text</text>" + | ||
| "</message>" + | ||
| "</messages>" + | ||
| "</Request>"; | ||
|
|
||
| @Test | ||
| public void testShouldSerialize() throws Exception { | ||
| Request givenRequest = _createRequest("given text"); | ||
|
|
||
| String actualXml = mapper.writeValueAsString(givenRequest); | ||
|
|
||
| assertEquals(expectedXML, actualXml); | ||
| } | ||
|
|
||
| @Test | ||
| public void testShouldDeserialize() throws Exception { | ||
| Request expected = _createRequest("given text"); | ||
|
|
||
| Request actualRequest = mapper.readValue(expectedXML, Request.class); | ||
|
|
||
| assertEquals(expected, actualRequest); | ||
| } | ||
|
|
||
| private Request _createRequest(String givenText) { | ||
| List<Message> messages = new ArrayList<>(); | ||
| messages.add(new Message(givenText)); | ||
| return new Request(messages); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be imported after
java.util.Listas per coding style.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done thank you!