Search in sources :

Example 41 with IJsonObject

use of com.helger.json.IJsonObject in project phoss-directory by phax.

the class PDIdentifier method getAsJson.

@Nonnull
public static IJsonObject getAsJson(@Nullable final String sScheme, @Nullable final String sValue) {
    final IJsonObject ret = new JsonObject();
    ret.add("scheme", sScheme);
    ret.add("value", sValue);
    return ret;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 42 with IJsonObject

use of com.helger.json.IJsonObject in project phoss-directory by phax.

the class PDBusinessCardTest method testJson.

@Test
public void testJson() {
    PDBusinessCard aBC = new PDBusinessCard(new PDIdentifier("a", "b"), new CommonsArrayList<>(_createBE(), _createBE().setAdditionalInfo("Gni gna gnu")));
    IJsonObject aJson = aBC.getAsJson();
    assertNotNull(aJson);
    PDBusinessCard aBC2 = PDBusinessCard.of(aJson);
    assertNotNull(aBC2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aBC2, aBC);
    // None set
    aBC = new PDBusinessCard(new PDIdentifier("a", "b"), null);
    aJson = aBC.getAsJson();
    assertNotNull(aJson);
    aBC2 = PDBusinessCard.of(aJson);
    assertNotNull(aBC2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aBC2, aBC);
}
Also used : IJsonObject(com.helger.json.IJsonObject) Test(org.junit.Test)

Example 43 with IJsonObject

use of com.helger.json.IJsonObject in project phoss-directory by phax.

the class PDContactTest method testJson.

@Test
public void testJson() {
    PDContact aContact = new PDContact("t", "n", "p", "e");
    IJsonObject aJson = aContact.getAsJson();
    assertNotNull(aJson);
    PDContact aContact2 = PDContact.of(aJson);
    assertNotNull(aContact2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
    // No type
    aContact = new PDContact(null, "n", "p", "e");
    aJson = aContact.getAsJson();
    assertNotNull(aJson);
    aContact2 = PDContact.of(aJson);
    assertNotNull(aContact2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
    // No name
    aContact = new PDContact("t", null, "p", "e");
    aJson = aContact.getAsJson();
    assertNotNull(aJson);
    aContact2 = PDContact.of(aJson);
    assertNotNull(aContact2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
    // No phone number
    aContact = new PDContact("t", "n", null, "e");
    aJson = aContact.getAsJson();
    assertNotNull(aJson);
    aContact2 = PDContact.of(aJson);
    assertNotNull(aContact2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
    // No email
    aContact = new PDContact("t", "n", "p", null);
    aJson = aContact.getAsJson();
    assertNotNull(aJson);
    aContact2 = PDContact.of(aJson);
    assertNotNull(aContact2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
    // None set
    aContact = new PDContact(null, null, null, null);
    aJson = aContact.getAsJson();
    assertNotNull(aJson);
    aContact2 = PDContact.of(aJson);
    assertNotNull(aContact2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
}
Also used : IJsonObject(com.helger.json.IJsonObject) Test(org.junit.Test)

Example 44 with IJsonObject

use of com.helger.json.IJsonObject in project phoss-directory by phax.

the class PDStoredBusinessEntity method getAsSearchResultJsonObject.

@Nonnull
public static IJsonObject getAsSearchResultJsonObject(@Nonnull @Nonempty final ICommonsList<PDStoredBusinessEntity> aDocs) {
    ValueEnforcer.notEmptyNoNullValue(aDocs, "Docs");
    final PDStoredBusinessEntity aFirst = aDocs.getFirst();
    final IJsonObject ret = new JsonObject();
    ret.addJson("participantID", _getIDAsJson(aFirst.m_aParticipantID.getScheme(), aFirst.m_aParticipantID.getValue()));
    // Add the items retrieved from SMP as well
    final IJsonArray aDocTypes = new JsonArray();
    for (final IDocumentTypeIdentifier aDocTypeID : aFirst.m_aDocumentTypeIDs) aDocTypes.add(_getIDAsJson(aDocTypeID.getScheme(), aDocTypeID.getValue()));
    if (aDocTypes.isNotEmpty())
        ret.addJson("docTypes", aDocTypes);
    final IJsonArray aEntities = new JsonArray();
    for (final PDStoredBusinessEntity aDoc : aDocs) {
        final IJsonObject aEntity = new JsonObject();
        // Multilingual names
        final IJsonArray aMLNames = new JsonArray();
        for (final PDStoredMLName aName : aDoc.m_aNames) aMLNames.add(_getMLNameAsJson(aName.getName(), aName.getLanguageCode()));
        if (aMLNames.isNotEmpty())
            aEntity.addJson("name", aMLNames);
        aEntity.add("countryCode", aDoc.m_sCountryCode);
        if (StringHelper.hasText(aDoc.m_sGeoInfo))
            aEntity.add("geoInfo", aDoc.m_sGeoInfo);
        final IJsonArray aIDs = new JsonArray();
        for (final PDStoredIdentifier aID : aDoc.m_aIdentifiers) aIDs.add(_getIDAsJson(aID.getScheme(), aID.getValue()));
        if (aIDs.isNotEmpty())
            aEntity.addJson("identifiers", aIDs);
        final IJsonArray aWebsites = new JsonArray();
        for (final String sWebsite : aDoc.m_aWebsiteURIs) aWebsites.add(sWebsite);
        if (aWebsites.isNotEmpty())
            aEntity.addJson("websites", aWebsites);
        final IJsonArray aContacts = new JsonArray();
        for (final PDStoredContact aContact : aDoc.m_aContacts) aContacts.add(new JsonObject().addIfNotNull("type", aContact.getType()).addIfNotNull("name", aContact.getName()).addIfNotNull("phone", aContact.getPhone()).addIfNotNull("email", aContact.getEmail()));
        if (aContacts.isNotEmpty())
            aEntity.addJson("contacts", aContacts);
        if (StringHelper.hasText(aDoc.m_sAdditionalInformation))
            aEntity.add("additionalInfo", aDoc.m_sAdditionalInformation);
        if (aDoc.m_aRegistrationDate != null)
            aEntity.add("regDate", PDTWebDateHelper.getAsStringXSD(aDoc.m_aRegistrationDate));
        aEntities.add(aEntity);
    }
    ret.addJson("entities", aEntities);
    return ret;
}
Also used : JsonArray(com.helger.json.JsonArray) IJsonArray(com.helger.json.IJsonArray) IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IJsonArray(com.helger.json.IJsonArray) Nonnull(javax.annotation.Nonnull)

Example 45 with IJsonObject

use of com.helger.json.IJsonObject in project phoss-directory by phax.

the class PDNameTest method testJson.

@Test
public void testJson() {
    PDName aName = new PDName("ACME", "en");
    IJsonObject aJson = aName.getAsJson();
    assertNotNull(aJson);
    PDName aName2 = PDName.of(aJson);
    assertNotNull(aName2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aName2, aName);
    // No language
    aName = new PDName("ACME");
    aJson = aName.getAsJson();
    assertNotNull(aJson);
    aName2 = PDName.of(aJson);
    assertNotNull(aName2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aName2, aName);
}
Also used : IJsonObject(com.helger.json.IJsonObject) Test(org.junit.Test)

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