void (@NotNull CodeStyleScheme scheme, @NotNull OutputStream outputStream, @Nullable List<String> languageNames) { GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); builder.registerTypeAdapter( CodeStyleSchemeJsonDescriptor.PropertyListHolder.class, new JsonSerializer<CodeStyleSchemeJsonDescriptor.PropertyListHolder>() { @Override public JsonElement serialize(CodeStyleSchemeJsonDescriptor.PropertyListHolder src, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); for (AbstractCodeStylePropertyMapper mapper : src) { JsonObject langProperties = serializeMapper(mapper); o.add( mapper.getLanguageDomainId(), langProperties ); } return o; } }); Gson gson = builder.create(); String json = gson.toJson(new CodeStyleSchemeJsonDescriptor(scheme, languageNames)); try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8))) { writer.write(json); } }