Skip to content

Commit

Permalink
Moved test case for issue FasterXML#81 from failing to package to tes…
Browse files Browse the repository at this point in the history
…t package.
  • Loading branch information
Pascal Gélinas committed Jan 28, 2014
1 parent 62b87e1 commit af3fee5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.fasterxml.jackson.dataformat.xml.failing;

import java.util.*;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.dataformat.xml.*;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;

public class TestPolymorphic extends XmlTestBase
{
Expand Down Expand Up @@ -56,20 +53,6 @@ public ClassArrayWrapper() { }
public ClassArrayWrapper(String s) { wrapped = new SubTypeWithClassArray(s); }
}

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
protected static class TypeWithClassPropertyAndObjectId {
public String id;

public TypeWithClassPropertyAndObjectId(String id) { this.id = id; }
}

protected static class Wrapper {
public List<TypeWithClassPropertyAndObjectId> data;

public Wrapper(List<TypeWithClassPropertyAndObjectId> data) { this.data = data; }
}

/*
/**********************************************************
/* Set up
Expand Down Expand Up @@ -114,22 +97,5 @@ public void testAsWrappedClassArray() throws Exception
assertEquals(SubTypeWithClassArray.class, result.wrapped.getClass());
assertEquals("Foobar", ((SubTypeWithClassArray) result.wrapped).name);
}

/**
* Test for issue 81
*/
public void testAsPropertyWithObjectId() throws Exception
{
List<TypeWithClassPropertyAndObjectId> data = new ArrayList<TestPolymorphic.TypeWithClassPropertyAndObjectId>();
TypeWithClassPropertyAndObjectId object = new TypeWithClassPropertyAndObjectId("Foobar");
data.add(object);
// This will be written as an id reference instead of object; as such, no type info will be written.
data.add(object);
String xml = _xmlMapper.writeValueAsString(new Wrapper(data));
Wrapper result = _xmlMapper.readValue(xml, Wrapper.class);
assertNotNull(result);
assertSame(result.data.get(0), result.data.get(1));
assertEquals("Foobar", result.data.get(0).id);
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.fasterxml.jackson.dataformat.xml.types;

import java.util.ArrayList;
import java.util.List;

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

Expand All @@ -22,9 +27,6 @@ public SubTypeWithClassProperty() { }
public SubTypeWithClassProperty(String s) { name = s; }
}

@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.WRAPPER_ARRAY)
static class BaseTypeWithClassArray { }

@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.WRAPPER_OBJECT)
protected static class BaseTypeWithClassObject { }

Expand All @@ -35,6 +37,22 @@ public SubTypeWithClassObject() { }
public SubTypeWithClassObject(String s) { name = s; }
}

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
protected static class TypeWithClassPropertyAndObjectId {
public String id;

public TypeWithClassPropertyAndObjectId() {}
public TypeWithClassPropertyAndObjectId(String id) { this.id = id; }
}

protected static class Wrapper {
public List<TypeWithClassPropertyAndObjectId> data;

public Wrapper(){}
public Wrapper(List<TypeWithClassPropertyAndObjectId> data) { this.data = data; }
}

/*
/**********************************************************
/* Set up
Expand Down Expand Up @@ -85,5 +103,22 @@ public void testAsClassObject() throws Exception
assertEquals(SubTypeWithClassObject.class, result.getClass());
assertEquals("Foobar", ((SubTypeWithClassObject) result).name);
}

/**
* Test for issue 81
*/
public void testAsPropertyWithObjectId() throws Exception
{
List<TypeWithClassPropertyAndObjectId> data = new ArrayList<TestPolymorphic.TypeWithClassPropertyAndObjectId>();
TypeWithClassPropertyAndObjectId object = new TypeWithClassPropertyAndObjectId("Foobar");
data.add(object);
// This will be written as an id reference instead of object; as such, no type info will be written.
data.add(object);
String xml = _xmlMapper.writeValueAsString(new Wrapper(data));
Wrapper result = _xmlMapper.readValue(xml, Wrapper.class);
assertNotNull(result);
assertSame(result.data.get(0), result.data.get(1));
assertEquals("Foobar", result.data.get(0).id);
}
}

0 comments on commit af3fee5

Please sign in to comment.