Skip to content

Added a unit test for issue 81. #82

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 1 commit into from
Dec 26, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Down Expand Up @@ -36,6 +41,20 @@ 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(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 @@ -86,5 +105,21 @@ 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);
}
}