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);
}
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 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 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 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;
}
Aggregations