package com.hubilon.json; import com.google.gson.Gson; import com.google.gson.GsonBuilder; /** * JSON serializer, backed by Gson. * * - disableHtmlEscaping(): keeps '<', '>', '=' etc. as literal characters * instead of <-style escapes -- this is an HTTP JSON API, not HTML. * - serializeNulls(): matches the previous hand-rolled writer's behavior, * e.g. a proxy result always carries "error": null rather than omitting * the key, which index.html's client-side code expects to see. */ public final class JsonWriter { private static final Gson GSON = new GsonBuilder() .disableHtmlEscaping() .serializeNulls() .create(); private JsonWriter() { } public static String write(Object value) { return GSON.toJson(value); } }