Skip to content

Commit

Permalink
Merge pull request #287 from rupert654/master
Browse files Browse the repository at this point in the history
Add failing test for #286
  • Loading branch information
cowtowncoder authored May 7, 2018
2 parents 449768c + 6f76888 commit 052675f
Showing 1 changed file with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.fasterxml.jackson.dataformat.xml.failing;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

public class UnwrappedJsonIdentityConflictTest extends XmlTestBase
{
static class Town
{
public School[] schools;
public Student[] students;
}

static class Student
{
public School school;
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "year")
public Year[] years;
}

static class Year
{
public String grade;
}

@JsonIdentityInfo(scope = School.class, generator = ObjectIdGenerators.PropertyGenerator.class,
property = "name")
static class School
{
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "staffMember")
public String[] staffMembers;
public String name;
}

public void testCaseInsensitiveComplex() throws Exception
{

XmlMapper mapper = XmlMapper.builder().build();

final String input =
"<town>\n"+
" <schools>\n"+
" <school name=\"Springfield Elementary\">\n"+
" <staffMember>Principal Skinner</staffMember>\n"+
" <staffMember>Groundskeeper Willie</staffMember>\n"+
" </school>\n"+
" </schools>\n"+
" <students>\n"+
" <student>\n"+
" <school>Springfield Elementary</school>\n"+
" <year>\n"+
" <grade>3</grade>\n"+
" </year>\n"+
" </student>\n"+
" </students>\n"+
"</town>";
Town result = mapper.readValue(input, Town.class);
assertNotNull(result);
assertEquals("Principal Skinner", result.schools[0].staffMembers[0]);
assertEquals("Principal Skinner", result.students[0].school.staffMembers[0]);
assertEquals("3", result.students[0].years[0].grade);
}
}

0 comments on commit 052675f

Please sign in to comment.