From 4e94a87e247f4fd4d2563d21c97ab84ee46abcba Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 28 May 2019 21:57:12 +0200 Subject: [PATCH] Let one pass an external ObjectMapper to JacksonRuntime instance Motivation: JacksonRuntime currently creates it own internal ObjectMapper instance. This ObjectMapper is used for parsing JSON String an emitting JsonLiteral instances. Jackson provides lots of features, see https://static.javadoc.io/com.fasterxml.jackson.core/jackson-core/2.9.9/com/fasterxml/jackson/core/JsonParser.Feature.html. Users might want to provide their own ObjectMapper instance configured for their needs (allowing numeric leading zeros, custom date formats, etc) or simply because they already have an instance and there's no reason the create a second one. Modification: Add a new constructor. Result: Users can provide their own ObjectMapper instance. --- .../main/java/io/burt/jmespath/jackson/JacksonRuntime.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jmespath-jackson/src/main/java/io/burt/jmespath/jackson/JacksonRuntime.java b/jmespath-jackson/src/main/java/io/burt/jmespath/jackson/JacksonRuntime.java index 87b3bb63..b6b95cbd 100644 --- a/jmespath-jackson/src/main/java/io/burt/jmespath/jackson/JacksonRuntime.java +++ b/jmespath-jackson/src/main/java/io/burt/jmespath/jackson/JacksonRuntime.java @@ -26,8 +26,12 @@ public JacksonRuntime() { } public JacksonRuntime(RuntimeConfiguration configuration) { + this(configuration, new ObjectMapper()); + } + + public JacksonRuntime(RuntimeConfiguration configuration, ObjectMapper jsonParser) { super(configuration); - this.jsonParser = new ObjectMapper(); + this.jsonParser = jsonParser; } @Override