Search in sources :

Example 21 with IJsonObject

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

the class PModeLegProtocolJsonConverter method convertToJson.

@Nonnull
public static IJsonObject convertToJson(@Nonnull final PModeLegProtocol aValue) {
    final IJsonObject ret = new JsonObject();
    if (aValue.hasAddress())
        ret.add(ADDRESS, aValue.getAddress());
    ret.add(SOAP_VERSION, aValue.getSoapVersion().getVersion());
    return ret;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 22 with IJsonObject

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

the class PModeJsonConverter method convertToNative.

@Nonnull
public static PMode convertToNative(@Nonnull final IJsonObject aElement) {
    final IJsonObject aInit = aElement.getAsObject(ELEMENT_INITIATOR);
    final PModeParty aInitiator = aInit == null ? null : PModePartyJsonConverter.convertToNative(aInit);
    final IJsonObject aResp = aElement.getAsObject(ELEMENT_RESPONDER);
    final PModeParty aResponder = aResp == null ? null : PModePartyJsonConverter.convertToNative(aResp);
    final String sAgreement = aElement.getAsString(ATTR_AGREEMENT);
    final String sMEP = aElement.getAsString(ATTR_MEP);
    final EMEP eMEP = EMEP.getFromIDOrNull(sMEP);
    if (eMEP == null)
        throw new IllegalStateException("Failed to resolve MEP '" + sMEP + "'");
    final String sMEPBinding = aElement.getAsString(ATTR_MEP_BINDING);
    final EMEPBinding eMEPBinding = EMEPBinding.getFromIDOrNull(sMEPBinding);
    if (eMEPBinding == null)
        throw new IllegalStateException("Failed to resolve MEPBinding '" + sMEPBinding + "'");
    final IJsonObject aL1 = aElement.getAsObject(ELEMENT_LEG1);
    final PModeLeg aLeg1 = aL1 == null ? null : PModeLegJsonConverter.convertToNative(aL1);
    final IJsonObject aL2 = aElement.getAsObject(ELEMENT_LEG2);
    final PModeLeg aLeg2 = aL2 == null ? null : PModeLegJsonConverter.convertToNative(aL2);
    final IJsonObject aPS = aElement.getAsObject(ELEMENT_PAYLOADSERVICE);
    final PModePayloadService aPayloadService = aPS == null ? null : PModePayloadServiceJsonConverter.convertToNative(aPS);
    final IJsonObject aRA = aElement.getAsObject(ELEMENT_RECEPETIONAWARENESS);
    final PModeReceptionAwareness aReceptionAwareness = aRA == null ? null : PModeReceptionAwarenessJsonConverter.convertToNative(aRA);
    return new PMode(getStubObject(aElement), aInitiator, aResponder, sAgreement, eMEP, eMEPBinding, aLeg1, aLeg2, aPayloadService, aReceptionAwareness);
}
Also used : EMEPBinding(com.helger.phase4.model.EMEPBinding) EMEP(com.helger.phase4.model.EMEP) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) IJsonObject(com.helger.json.IJsonObject) Nonnull(javax.annotation.Nonnull)

Example 23 with IJsonObject

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

the class PModeJsonConverter method setObjectFields.

public static void setObjectFields(@Nonnull final IBusinessObject aValue, @Nonnull final IJsonObject aElement) {
    aElement.add(ATTR_ID, aValue.getID());
    if (aValue.hasCreationDateTime())
        aElement.add(ATTR_CREATIONLDT, PDTWebDateHelper.getAsStringXSD(aValue.getCreationDateTime()));
    if (aValue.hasCreationUserID())
        aElement.add(ATTR_CREATIONUSERID, aValue.getCreationUserID());
    if (aValue.hasLastModificationDateTime())
        aElement.add(ATTR_LASTMODLDT, PDTWebDateHelper.getAsStringXSD(aValue.getLastModificationDateTime()));
    if (aValue.hasLastModificationUserID())
        aElement.add(ATTR_LASTMODUSERID, aValue.getLastModificationUserID());
    if (aValue.hasDeletionDateTime())
        aElement.add(ATTR_DELETIONLDT, PDTWebDateHelper.getAsStringXSD(aValue.getDeletionDateTime()));
    if (aValue.hasDeletionUserID())
        aElement.add(ATTR_DELETIONUSERID, aValue.getDeletionUserID());
    if (aValue.attrs().isNotEmpty()) {
        final IJsonArray aCustomArray = new JsonArray();
        for (final Map.Entry<String, String> aEntry : CollectionHelper.getSortedByKey(aValue.attrs()).entrySet()) {
            final IJsonObject eCustom = new JsonObject();
            eCustom.add(ATTR_ID, aEntry.getKey());
            if (aEntry.getValue() != null)
                eCustom.add(VALUE, aEntry.getValue());
            aCustomArray.add(eCustom);
        }
        aElement.addJson(ELEMENT_CUSTOM, aCustomArray);
    }
}
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) IJsonArray(com.helger.json.IJsonArray) ICommonsOrderedMap(com.helger.commons.collection.impl.ICommonsOrderedMap) Map(java.util.Map) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap)

Example 24 with IJsonObject

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

the class PModeJsonConverter method getStubObject.

@Nonnull
public static StubObject getStubObject(@Nonnull final IJsonObject aElement) {
    // ID
    final String sID = aElement.getAsString(ATTR_ID);
    // Creation
    final LocalDateTime aCreationLDT = PDTWebDateHelper.getLocalDateTimeFromXSD(aElement.getAsString(ATTR_CREATIONLDT));
    final String sCreationUserID = aElement.getAsString(ATTR_CREATIONUSERID);
    // Last modification
    final LocalDateTime aLastModificationLDT = PDTWebDateHelper.getLocalDateTimeFromXSD(aElement.getAsString(ATTR_LASTMODLDT));
    final String sLastModificationUserID = aElement.getAsString(ATTR_LASTMODUSERID);
    // Deletion
    final LocalDateTime aDeletionLDT = PDTWebDateHelper.getLocalDateTimeFromXSD(aElement.getAsString(ATTR_DELETIONLDT));
    final String sDeletionUserID = aElement.getAsString(ATTR_DELETIONUSERID);
    final ICommonsOrderedMap<String, String> aCustomAttrs = new CommonsLinkedHashMap<>();
    final IJsonArray aCustom = aElement.getAsArray(ELEMENT_CUSTOM);
    if (aCustom != null)
        for (final IJsonObject eCustom : aCustom.iteratorObjects()) aCustomAttrs.put(eCustom.getAsString(ATTR_ID), eCustom.getAsString(VALUE));
    return new StubObject(sID, aCreationLDT, sCreationUserID, aLastModificationLDT, sLastModificationUserID, aDeletionLDT, sDeletionUserID, aCustomAttrs);
}
Also used : LocalDateTime(java.time.LocalDateTime) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) IJsonObject(com.helger.json.IJsonObject) IJsonArray(com.helger.json.IJsonArray) StubObject(com.helger.photon.security.object.StubObject) Nonnull(javax.annotation.Nonnull)

Example 25 with IJsonObject

use of com.helger.json.IJsonObject in project ph-commons by phax.

the class SettingsPersistenceJson method writeSettings.

@Nonnull
public ESuccess writeSettings(@Nonnull final ISettings aSettings, @Nonnull @WillClose final OutputStream aOS) {
    ValueEnforcer.notNull(aOS, "OutputStream");
    try {
        final IJsonObject aProps = new JsonObject();
        for (final Map.Entry<String, Object> aEntry : CollectionHelper.getSorted(aSettings.entrySet(), Comparator.comparing(Map.Entry::getKey))) {
            final String sName = aEntry.getKey();
            final Object aValue = aEntry.getValue();
            final String sValue = TypeConverter.convert(aValue, String.class);
            aProps.add(sName, sValue);
        }
        final JsonWriterSettings aJWS = new JsonWriterSettings();
        aJWS.setIndentEnabled(true);
        aJWS.setQuoteNames(false);
        // Does not close the output stream!
        new JsonWriter(aJWS).writeToWriterAndClose(aProps, StreamHelper.createWriter(aOS, m_aCharset));
        return ESuccess.SUCCESS;
    } catch (final IOException ex) {
        LOGGER.error("Failed to write settings to JSON file", ex);
        return ESuccess.FAILURE;
    } finally {
        StreamHelper.close(aOS);
    }
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) JsonWriterSettings(com.helger.json.serialize.JsonWriterSettings) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) IOException(java.io.IOException) Map(java.util.Map) JsonWriter(com.helger.json.serialize.JsonWriter) Nonnull(javax.annotation.Nonnull)

Aggregations

IJsonObject (com.helger.json.IJsonObject)77 JsonObject (com.helger.json.JsonObject)43 Nonnull (javax.annotation.Nonnull)39 IJsonArray (com.helger.json.IJsonArray)21 JsonArray (com.helger.json.JsonArray)18 Test (org.junit.Test)15 JsonWriter (com.helger.json.serialize.JsonWriter)11 IJson (com.helger.json.IJson)10 Map (java.util.Map)10 StopWatch (com.helger.commons.timing.StopWatch)9 ZonedDateTime (java.time.ZonedDateTime)9 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)8 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