From a640781deb48ee9ed29a49e244571f8b873d3eca Mon Sep 17 00:00:00 2001 From: Hammy Date: Mon, 14 Jun 2021 02:06:15 +0100 Subject: [PATCH] Add method to support retrieving objects as strings --- src/main/java/me/goudham/APIMapper.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/me/goudham/APIMapper.java b/src/main/java/me/goudham/APIMapper.java index e7d460d..a78ade4 100644 --- a/src/main/java/me/goudham/APIMapper.java +++ b/src/main/java/me/goudham/APIMapper.java @@ -22,6 +22,14 @@ class APIMapper { objectMapper = new ObjectMapper(); } + String getValueAsString(Object obj) throws APIMapperException { + try { + return objectMapper.writeValueAsString(obj); + } catch (JsonProcessingException jpe) { + throw new APIMapperException(jpe.getMessage(), jpe); + } + } + /** * Using the given {@code model}, {@link ObjectMapper} deserializes the given Json * into a Java POJO