use of org.json.JSONWriter in project OpenRefine by OpenRefine.
the class GetStarredExpressionsCommand method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
List<String> starredExpressions = ((TopList) ProjectManager.singleton.getPreferenceStore().get("scripting.starred-expressions")).getList();
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter());
writer.object();
writer.key("expressions");
writer.array();
for (String s : starredExpressions) {
writer.object();
writer.key("code");
writer.value(s);
writer.endObject();
}
writer.endArray();
writer.endObject();
} catch (Exception e) {
respondException(response, e);
}
}
use of org.json.JSONWriter in project OpenRefine by OpenRefine.
the class ProjectMetadataUtilities method saveToFile.
protected static void saveToFile(ProjectMetadata projectMeta, File metadataFile) throws JSONException, IOException {
Writer writer = new OutputStreamWriter(new FileOutputStream(metadataFile));
try {
JSONWriter jsonWriter = new JSONWriter(writer);
projectMeta.write(jsonWriter);
} finally {
writer.close();
}
}
use of org.json.JSONWriter in project ig-json-parser by Instagram.
the class DeserializeTest method fieldAssignmentTest.
@Test
public void fieldAssignmentTest() throws IOException, JSONException {
final int encodedValue = 25;
final int deserializedValue = -encodedValue;
StringWriter stringWriter = new StringWriter();
JSONWriter writer = new JSONWriter(stringWriter);
writer.object().key(FormatterUUT.FIELD_ASSIGNMENT_FIELD_NAME).value(encodedValue).endObject();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
FormatterUUT uut = FormatterUUT__JsonHelper.parseFromJson(jp);
assertSame(deserializedValue, uut.getFieldAssignmentFormatter());
}
use of org.json.JSONWriter in project ig-json-parser by Instagram.
the class DeserializeTest method enumTest.
@Test
public void enumTest() throws IOException, JSONException {
final EnumUUT.EnumType value = EnumUUT.EnumType.VALUE2;
StringWriter stringWriter = new StringWriter();
JSONWriter writer = new JSONWriter(stringWriter);
writer.object().key(EnumUUT.ENUM_FIELD_NAME).value(value.toString()).endObject();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
EnumUUT uut = EnumUUT__JsonHelper.parseFromJson(jp);
assertSame(value, uut.enumField);
}
use of org.json.JSONWriter in project ig-json-parser by Instagram.
the class DeserializeTest method TypeFormatterImportsTest.
@Test
public void TypeFormatterImportsTest() throws IOException, JSONException {
final String encodedValue = "test";
StringWriter stringWriter = new StringWriter();
JSONWriter writer = new JSONWriter(stringWriter);
writer.object().key("callee_ref").object().key("string_field").value(encodedValue).endObject().endObject();
String inputString = stringWriter.toString();
TypeFormatterImportsContainerUUT container = TypeFormatterImportsContainerUUT__JsonHelper.parseFromJson(inputString);
TypeFormatterImportsUUT uut = container.mTypeFormatterImports;
assertTrue(uut instanceof TypeFormatterImportsCompanionUUT);
assertEquals(encodedValue, uut.mString);
}
Aggregations