Issue 634 in google-gson: Gson not populating fields on Object created with InstanceCreator

3 views
Skip to first unread message

googl...@googlecode.com

unread,
Mar 31, 2015, 3:26:30 PM3/31/15
to google-gson...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 634 by kcar...@dstillery.com: Gson not populating fields on
Object created with InstanceCreator
https://code.google.com/p/google-gson/issues/detail?id=634

What steps will reproduce the problem?
Run the following test:
{code}

@Test
public void testParseFloat() {
Parsed value = new
GsonBuilder().registerTypeAdapter(Container.class,
new
FloatContainerInstanceCreator())
.create().fromJson("{\"container\":{\"value\":0.0024}}",
Parsed.class);
Assert.assertEquals(0.0024f, value.getContainer().getValue(),
0.00001f);
}

private static class FloatContainerInstanceCreator implements
InstanceCreator<Container> {

@Override
public Container createInstance(Type arg0) {
return new FloatContainer(0f);
}

}

private static class Parsed {
private Container container;

public Container getContainer() {
return container;
}
}

private static abstract class Container {
public abstract float getValue();
}

private static class FloatContainer extends Container {
private final float value;

public FloatContainer(float value) {
this.value = value;
}

@Override
public float getValue() {
return value;
}
}
{code}

What is the expected output? What do you see instead?
I expect the test to pass. The test fails.

What version of the product are you using? On what operating system?
Under Gson 2.3.1 this test fails. However in Gson 1.7.1 it will pass. I'm
on OSX 10.9.5 and using java 1.8.0_25

Please provide any additional information below.
The bug happens whether Container is an abstract class or an interface. It
is definitely something around the class hierarchy though. The code works
if Parsed contains a FloatContainer.


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
Reply all
Reply to author
Forward
0 new messages