I have a method called JsonMarshall(T t)
that takes an object and converts it into Json String. Inside this method I'm using the Objectmapper
to accomplish this task:
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(t)
Now, lets say I have a class ClientName
with the attributes Title and Name that I'm using for my test. Now when I try to convert ClientName
into json string with my method and test this method by asserting its output against some expected Json String such as:
expectedString = "{\"title\":\"RandomTitle",\"Name\":\"RandomName\"}"
I get two scenarios:
Test fails when I use
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(t)
in my method.Test passes when I only do
mapper.writeValueAsString(t)
So I guess the indentation of the writerWithDefaultPrettyPrinter()
is causing the test to fail.
Any ideas how I can go about making this test pass for the first scenario?