-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
Hiya,
There seems to be an issue with the ObjectReader objects not taking into account the configuration set in them instead of the main object mapper instance.
Here is a simple example:
Having this inner class:
static class Data {
enum Type {
A, B, C;
@Override
public String toString() {
return this.name().toLowerCase();
};
};
private final Type type;
private final String value;
@JsonCreator
public Data(//
@JsonProperty("type") Type type, //
@JsonProperty("value") String value) {
this.type = type;
this.value = value;
}
@Override
public String toString() {
return "Data [type=" + type + ", value=" + value + "]";
}
}
The following will fail with an exception when parsing the enum:
final String src = "[ { \"type\": \"a\", \"value\": \"1\" }, { \"type\": \"b\", \"value\": \"2\" }]";
final ObjectMapper mapper = new ObjectMapper();
MappingIterator<Data> iterator = mapper //
.readerFor(Data.class) //
.with(DeserializationFeature.READ_ENUMS_USING_TO_STRING) //
.readValues(src);
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
to get it to work it seems we need to move the DeserializationFeature configuration to the ObjectMapper itself:
final String src = "[ { \"type\": \"a\", \"value\": \"1\" }, { \"type\": \"b\", \"value\": \"2\" }]";
final ObjectMapper mapper = new ObjectMapper() //
.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);
MappingIterator<Data> iterator = mapper //
.readerFor(Data.class) //
.readValues(src);
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
Tested with both version 2.7.1-1 and 2.7.2.
Metadata
Metadata
Assignees
Labels
No labels