use of com.helger.json.IJsonObject in project phoss-directory by phax.
the class PDExtendedBusinessCard method getAsJson.
@Nonnull
public IJsonObject getAsJson() {
final IJsonObject ret = new JsonObject();
ret.addJson("businesscard", m_aBusinessCard.getAsJson());
ret.addJson("doctypes", new JsonArray().addAllMapped(m_aDocumentTypeIDs, x -> PDIdentifier.getAsJson(x.getScheme(), x.getValue())));
return ret;
}
use of com.helger.json.IJsonObject in project phoss-directory by phax.
the class PDIdentifierTest method testJson.
@Test
public void testJson() {
PDIdentifier aID = new PDIdentifier("s", "v");
IJsonObject aJson = aID.getAsJson();
assertNotNull(aJson);
PDIdentifier aID2 = PDIdentifier.of(aJson);
assertNotNull(aID2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aID2, aID);
// No scheme
aID = new PDIdentifier(null, "v");
aJson = aID.getAsJson();
assertNotNull(aJson);
aID2 = PDIdentifier.of(aJson);
assertNotNull(aID2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aID2, aID);
// No value
aID = new PDIdentifier("v", null);
aJson = aID.getAsJson();
assertNotNull(aJson);
aID2 = PDIdentifier.of(aJson);
assertNotNull(aID2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aID2, aID);
// Neither nor
aID = new PDIdentifier(null, null);
aJson = aID.getAsJson();
assertNotNull(aJson);
aID2 = PDIdentifier.of(aJson);
assertNotNull(aID2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aID2, aID);
}
use of com.helger.json.IJsonObject in project phoss-directory by phax.
the class PDBusinessEntityTest method testJson.
@Test
public void testJson() {
final LocalDate aToday = PDTFactory.getCurrentLocalDate();
PDBusinessEntity aBE = new PDBusinessEntity(new CommonsArrayList<>(new PDName("Philip", "en"), new PDName("Helger", "es")), "AT", "geo", new CommonsArrayList<>(new PDIdentifier("s1", "v1"), new PDIdentifier("s2", "v2")), new CommonsArrayList<>("uri1", "uri2", "uri3"), new CommonsArrayList<>(new PDContact("t", "n", "p", "e"), new PDContact("t2", "n2", "p2", "e2")), "additional info", aToday);
IJsonObject aJson = aBE.getAsJson();
assertNotNull(aJson);
PDBusinessEntity aBE2 = PDBusinessEntity.of(aJson);
assertNotNull(aBE2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aBE2, aBE);
// None set
aBE = new PDBusinessEntity(new CommonsArrayList<>(new PDName("Philip")), "AT", null, null, null, null, null, null);
aJson = aBE.getAsJson();
assertNotNull(aJson);
aBE2 = PDBusinessEntity.of(aJson);
assertNotNull(aBE2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aBE2, aBE);
}
use of com.helger.json.IJsonObject in project phoss-directory by phax.
the class PDName method getAsJson.
@Nonnull
public IJsonObject getAsJson() {
final IJsonObject ret = new JsonObject();
ret.add("name", m_sName);
if (m_sLanguageCode != null)
ret.add("language", m_sLanguageCode);
return ret;
}
use of com.helger.json.IJsonObject in project phoss-directory by phax.
the class ExportAllManager method writeFileParticipantJSON.
@Nonnull
static ESuccess writeFileParticipantJSON() throws IOException {
final IJsonObject aObj = queryAllContainedParticipantsAsJSON();
final File f = _getInternalFileParticipantJSON();
// Do it in a write lock!
RW_LOCK.writeLock().lock();
try (final Writer aWriter = FileHelper.getBufferedWriter(f, StandardCharsets.UTF_8)) {
new JsonWriter().writeToWriterAndClose(aObj, aWriter);
LOGGER.info("Successfully wrote all Participants as JSON to " + f.getAbsolutePath());
} catch (final IOException ex) {
LOGGER.error("Failed to export all Participants as JSON to " + f.getAbsolutePath(), ex);
} finally {
RW_LOCK.writeLock().unlock();
}
return ESuccess.SUCCESS;
}
Aggregations