Search in sources :

Example 6 with IJsonObject

use of com.helger.json.IJsonObject in project phive by phax.

the class PhiveRestoredExceptionTest method testBasic.

@Test
public void testBasic() {
    final Exception ex = new IllegalArgumentException("bla foo");
    // to Json
    final IJsonObject aObj = PhiveJsonHelper.getJsonStackTrace(ex);
    assertNotNull(aObj);
    // from Json
    final PhiveRestoredException aRSS = PhiveRestoredException.createFromJson(aObj);
    assertNotNull(aRSS);
    assertEquals("java.lang.IllegalArgumentException", aRSS.getClassName());
    assertEquals("bla foo", aRSS.getMessage());
    assertTrue(aRSS.getAllStackTraceLines().isNotEmpty());
    // Name of this method must occur
    assertTrue(aRSS.getAllStackTraceLines().containsAny(x -> x.contains("testBasic")));
    final IJsonObject aObj2 = aRSS.getAsJson();
    assertNotNull(aObj2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aObj, aObj2);
}
Also used : Assert.assertNull(org.junit.Assert.assertNull) CommonsTestHelper(com.helger.commons.mock.CommonsTestHelper) Assert.assertNotNull(org.junit.Assert.assertNotNull) IJsonObject(com.helger.json.IJsonObject) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.assertEquals(org.junit.Assert.assertEquals) IJsonObject(com.helger.json.IJsonObject) Test(org.junit.Test)

Example 7 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 8 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 9 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 10 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)

Aggregations

IJsonObject (com.helger.json.IJsonObject)67 JsonObject (com.helger.json.JsonObject)38 Nonnull (javax.annotation.Nonnull)34 IJsonArray (com.helger.json.IJsonArray)16 JsonArray (com.helger.json.JsonArray)16 Test (org.junit.Test)15 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)7 IError (com.helger.commons.error.IError)6 StopWatch (com.helger.commons.timing.StopWatch)5 IJson (com.helger.json.IJson)5 JsonWriter (com.helger.json.serialize.JsonWriter)5 Map (java.util.Map)5 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)4 ZonedDateTime (java.time.ZonedDateTime)4 Nullable (javax.annotation.Nullable)4 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)3 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)3 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)3 SimpleLocation (com.helger.commons.location.SimpleLocation)3