Closed GoogleCodeExporter closed 9 years ago
oh damn. I forgot to remove the setExclusionStrategies - Part. The actual
version of the method is:
private static ObjectMapperConfig getGsonObjectMapperConfig() {
return ObjectMapperConfig.objectMapperConfig().gsonObjectMapperFactory(new GsonObjectMapperFactory() {
public Gson create(Class cls, String charset) {
return new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
}
});
}
Original comment by roth.ben...@gmail.com
on 28 Nov 2012 at 10:46
[deleted comment]
Are you sure that GSON is actually used? If you have multiple Json mappers in
classpath GSON may not be picked by classpath scanning. You can configure
RestAssured to always use GSON by specifying the "defaultObjectMapperType" to
GSON in the ObjectMapperConfig. Please tell me if this works.
Original comment by johan.ha...@gmail.com
on 29 Nov 2012 at 7:13
I couldn't find the aforementioned setter methods so I tried using the
following instead:
RestAssuredConfig restAssuredConfig = new RestAssuredConfig();
restAssuredConfig.decoderConfig(new DecoderConfig("UTF-8"));
restAssuredConfig.encoderConfig(new EncoderConfig("UTF-8", "UTF-8"));
restAssuredConfig.objectMapperConfig(ObjectMapperConfig.objectMapperConfig().def
aultObjectMapperType(ObjectMapperType.GSON)); // (1)
restAssuredConfig.objectMapperConfig(getGsonObjectMapperConfig()); // (2)
RestAssured.config = restAssuredConfig;
I couldnt find any other way to set the default object mapper but my guess
would be that (1) would get overwritten by (2).
The code above does not work at all. Not even the encoding settings are picked
up. Is it possible that the setter methods (setEncoderConfig, etc... are not
part of RestAssured Version 1.7.1)?
Original comment by roth.ben...@gmail.com
on 30 Nov 2012 at 9:51
Actually the implementation didn't work as I though it would, I'm sorry to
confuse you. The RestAssuredConfig is immutable so just as you say the examples
that you show overrides one another. Try something like this:
RestAssured.config = new RestAssuredConfig().
decoderConfig(
new DecoderConfig("UTF-8")
).encoderConfig(
new EncoderConfig("UTF-8", "UTF-8")
).objectMapperConfig(
new ObjectMapperConfig(GSON).
gsonObjectMapperFactory(myCustomObjectMapperFactory())
);
I can see that this is very confusing. Try it and see if it works.
Original comment by johan.ha...@gmail.com
on 30 Nov 2012 at 10:53
Works like a charm. Thanks a lot.
Original comment by roth.ben...@gmail.com
on 4 Dec 2012 at 1:37
Great! I'll see if it can make it simpler in the future.
Original comment by johan.ha...@gmail.com
on 4 Dec 2012 at 1:51
I won't take any further action on this now.
Original comment by johan.ha...@gmail.com
on 5 Dec 2012 at 9:10
Original issue reported on code.google.com by
roth.ben...@gmail.com
on 28 Nov 2012 at 10:34