use of com.github.openjson.JSONArray in project openmeetings by apache.
the class WebSocketHelper method getMessage.
public static JSONObject getMessage(User curUser, List<ChatMessage> list, BiConsumer<JSONObject, User> uFmt) {
JSONArray arr = new JSONArray();
final FastDateFormat fullFmt = FormatHelper.getDateTimeFormat(curUser);
final FastDateFormat dateFmt = FormatHelper.getDateFormat(curUser);
final FastDateFormat timeFmt = FormatHelper.getTimeFormat(curUser);
for (ChatMessage m : list) {
String smsg = m.getMessage();
smsg = smsg == null ? smsg : " " + smsg.replaceAll(" ", " ") + " ";
JSONObject from = new JSONObject().put("id", m.getFromUser().getId()).put("displayName", m.getFromName()).put("name", getDisplayName(m.getFromUser()));
if (uFmt != null) {
uFmt.accept(from, m.getFromUser());
}
arr.put(setScope(new JSONObject(), m, curUser.getId()).put("id", m.getId()).put("message", smsg).put("from", from).put("actions", curUser.getId() == m.getFromUser().getId() ? "short" : "full").put("sent", fullFmt.format(m.getSent())).put("date", dateFmt.format(m.getSent())).put("time", timeFmt.format(m.getSent())));
}
return new JSONObject().put("type", "chat").put("msg", arr);
}
use of com.github.openjson.JSONArray in project triplea by triplea-game.
the class DownloadFileParser method parse.
public static List<DownloadFileDescription> parse(final InputStream is) {
final JSONArray yamlData = new JSONArray(new Yaml().loadAs(is, List.class));
final List<DownloadFileDescription> downloads = new ArrayList<>();
OpenJsonUtils.stream(yamlData).map(JSONObject.class::cast).forEach(yaml -> {
final String url = yaml.getString(Tags.url.toString());
final String description = yaml.getString(Tags.description.toString());
final String mapName = yaml.getString(Tags.mapName.toString());
final Version version = new Version(yaml.getInt(Tags.version.toString()), 0);
final DownloadFileDescription.DownloadType downloadType = OpenJsonUtils.optEnum(yaml, DownloadFileDescription.DownloadType.class, Tags.mapType.toString(), DownloadFileDescription.DownloadType.MAP);
final DownloadFileDescription.MapCategory mapCategory = OpenJsonUtils.optEnum(yaml, DownloadFileDescription.MapCategory.class, Tags.mapCategory.toString(), DownloadFileDescription.MapCategory.EXPERIMENTAL);
final String img = yaml.optString(Tags.img.toString());
final DownloadFileDescription dl = new DownloadFileDescription(url, description, mapName, version, downloadType, mapCategory, img);
downloads.add(dl);
});
return downloads;
}
use of com.github.openjson.JSONArray in project triplea by triplea-game.
the class OpenJsonUtilsTest method streamJsonArray_ShouldReturnStreamContainingJsonArrayElements.
@Test
public void streamJsonArray_ShouldReturnStreamContainingJsonArrayElements() {
final JSONArray jsonArray = new JSONArray(Arrays.asList("text", 1, 1.0));
final List<Object> elements = OpenJsonUtils.stream(jsonArray).collect(Collectors.toList());
assertThat(elements, is(Arrays.asList("text", 1, 1.0)));
}
use of com.github.openjson.JSONArray in project triplea by triplea-game.
the class OpenJsonUtilsTest method streamJsonArray_ShouldNotConvertJsonArrayValue.
@Test
public void streamJsonArray_ShouldNotConvertJsonArrayValue() {
final List<Object> expectedElements = Arrays.asList(new JSONArray(Arrays.asList(42)));
final JSONArray jsonArray = new JSONArray(expectedElements);
final List<Object> actualElements = OpenJsonUtils.stream(jsonArray).collect(Collectors.toList());
assertThat(actualElements, is(expectedElements));
}
use of com.github.openjson.JSONArray in project triplea by triplea-game.
the class OpenJsonUtilsTest method toList_ShouldConvertJsonArrayValueToList.
@Test
public void toList_ShouldConvertJsonArrayValueToList() {
final JSONArray jsonArray = new JSONArray(Arrays.asList(new JSONArray(Arrays.asList(42))));
final List<Object> elements = OpenJsonUtils.toList(jsonArray);
assertThat(elements, is(Arrays.asList(Arrays.asList(42))));
}
Aggregations