Search in sources :

Example 31 with IJsonObject

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;
}
Also used : JsonArray(com.helger.json.JsonArray) Nonnegative(javax.annotation.Nonnegative) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) IHasJson(com.helger.json.IHasJson) PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) Predicate(java.util.function.Predicate) IJsonObject(com.helger.json.IJsonObject) ToStringGenerator(com.helger.commons.string.ToStringGenerator) JsonObject(com.helger.json.JsonObject) Serializable(java.io.Serializable) ValueEnforcer(com.helger.commons.ValueEnforcer) JsonArray(com.helger.json.JsonArray) PDIdentifier(com.helger.pd.businesscard.generic.PDIdentifier) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IJson(com.helger.json.IJson) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull) Immutable(javax.annotation.concurrent.Immutable) Nullable(javax.annotation.Nullable) IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 32 with IJsonObject

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);
}
Also used : IJsonObject(com.helger.json.IJsonObject) Test(org.junit.Test)

Example 33 with IJsonObject

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);
}
Also used : IJsonObject(com.helger.json.IJsonObject) LocalDate(java.time.LocalDate) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Test(org.junit.Test)

Example 34 with IJsonObject

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;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 35 with IJsonObject

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;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IOException(java.io.IOException) File(java.io.File) JsonWriter(com.helger.json.serialize.JsonWriter) CSVWriter(com.helger.commons.csv.CSVWriter) Writer(java.io.Writer) JsonWriter(com.helger.json.serialize.JsonWriter) MicroWriter(com.helger.xml.microdom.serialize.MicroWriter) Nonnull(javax.annotation.Nonnull)

Aggregations

IJsonObject (com.helger.json.IJsonObject)79 JsonObject (com.helger.json.JsonObject)44 Nonnull (javax.annotation.Nonnull)41 IJsonArray (com.helger.json.IJsonArray)22 JsonArray (com.helger.json.JsonArray)19 Test (org.junit.Test)15 JsonWriter (com.helger.json.serialize.JsonWriter)12 IJson (com.helger.json.IJson)10 Map (java.util.Map)10 StopWatch (com.helger.commons.timing.StopWatch)9 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 ZonedDateTime (java.time.ZonedDateTime)9 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)7 IError (com.helger.commons.error.IError)7 PDBusinessCard (com.helger.pd.businesscard.generic.PDBusinessCard)5 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)5 Nullable (javax.annotation.Nullable)5 Nonempty (com.helger.commons.annotation.Nonempty)4 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)3 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)3