If you can handle serializing the object yourself, this should do the trick:
import com.squareup.moshi.JsonWriter; import com.squareup.moshi.Moshi; import java.io.IOException; import okio.Buffer; public class MoshiPrettyPrintingTest { private static class Dude { public final String firstName = "Jeff"; public final String lastName = "Lebowski"; } public static void main(String[] args) throws IOException { final Moshi moshi = new Moshi.Builder().build(); final Buffer buffer = new Buffer(); final JsonWriter jsonWriter = JsonWriter.of(buffer);
Fingerprints:
{ "firstName": "Jeff", "lastName": "Lebowski" }
See prettyPrintObject() for this test file and source code for BufferedSinkJsonWriter .
However, I still do not understand whether and how to do this if you are using Moshi with refinement.
source share