Skip to content

Constructor binding not compatible with setter binding in reflection decoding mode #152

@cedrilino

Description

@cedrilino

Having a constructor binding (@JsonCreator) simultaneously with a setter binding (@JsonWrapper) fails with an exception.
The test

public class JsonIterTest {

	@BeforeClass
	public static void setUp() {
		JsonIterator.setMode(DecodingMode.REFLECTION_MODE);
	}

	public static class TestObject {

		@JsonIgnore
		private final String id;
		@JsonIgnore
		private final Properties properties;

		@JsonCreator
		public TestObject(@JsonProperty("name") final String name) {
			this.id = name;
			properties = new Properties();
		}

		@JsonWrapper
		public void setProperties(@JsonProperty("props") final Any props) {
			// Set props
		}
	}

	@Test
	public void simpleParsingTest() throws IOException {
		JsonIterator iter = JsonIterator.parse("{\"name\": \"test\", \"props\": {\"val\": \"42\"}}");
		TestObject t = iter.read(TestObject.class);
	}
}

fails with:

java.lang.IllegalArgumentException: argument type mismatch

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.jsoniter.ReflectionObjectDecoder$WithCtor.decode_(ReflectionObjectDecoder.java:250)
	at com.jsoniter.ReflectionObjectDecoder$WithCtor.decode(ReflectionObjectDecoder.java:184)
	at com.jsoniter.JsonIterator.read(JsonIterator.java:369)
	at com.jsoniter.JsonIterator.read(JsonIterator.java:359)
	...

while either

  • setting the decoding mode to either DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH or DYNAMIC_MODE_AND_MATCH_FIELD_STRICTLY
  • renaming the properties variable to props

passes the test.

Tested with jsoniter:0.9.19-20171209.154235-2 and jsoniter:0.9.21-20180126.090524-2 with javassist:3.20.0-GA.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions