-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
Hi, I've faced with a problem that is too similar this one #941. I expect that "{}" will be parsed correctly to empty Map when I'm using @JsonCreator
I've found that this case is invalid https://github.com/FasterXML/jackson-databind/blob/jackson-databind-2.6.3/src/main/java/com/fasterxml/jackson/databind/deser/std/UntypedObjectDeserializer.java#L272, but why?
Here is the minimum code to reproduce:
import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static void main(String[] args) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.readValue("[]", SomeObjectThatCanBeAggregated.class);
mapper.readValue("[{}]", SomeObjectThatCanBeAggregated.class);
mapper.readValue("{\"key\":null}", SomeObjectThatCanBeAggregated.class);
mapper.readValue("{}", SomeObjectThatCanBeAggregated.class);
}
}
class SomeObjectThatCanBeAggregated {
@JsonCreator
public SomeObjectThatCanBeAggregated(Object obj) {
System.out.println(obj + " //" + obj.getClass());
}
}
Output:
[] //class java.util.ArrayList
[{}] //class java.util.ArrayList
{key=null} //class java.util.LinkedHashMap
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.Object out of END_OBJECT token
at [Source: {}; line: 1, column: 2]
...
Metadata
Metadata
Assignees
Labels
No labels