| Docs Help
  AppSource  
Docs  /  NVXSUL Serialization Utility Library  /  Tasks

Working with the App


2023/10/23 • 2 min. to read
The Serialize procedures of the Codeunit SULSerializationUtilNVX can be called by an dependent Extension, which require various Parameters:

Parameter

  • VarToSerialize: Variant -> the Type which shall be serialized
  • ISerializer: Interface SULISerializerNVX -> Implementation of Serialization e.g. JSON
  • SerializableType: Enum SULSerializableTypeNVX -> Type of the serializable Datatype
  • FieldNoSelection: List of [Integer] -> Selection of fields to be serialized (only viable for Record and RecordRef Datatypes)
Further Serialization formats e.g. XML must be implemented by using the Interface SULISerializerNVX and the Enum SULSerializerTypeNVX.

JSON Serialization of Records

procedure GetCustomerAsJSONObject(Customer: Record Customer): JsonObject
var
    SerializationUtil: Codeunit SULSerializationUtilNVX;    
    JObject: JsonObject;
    BodyContent: Text;
begin
    BodyContent := SerializationUtil.Serialize(Customer, Enum::SULSerializerTypeNVX::JSON, Enum::SULSerializableTypeNVX::Record);
    exit(JObject.WriteTo(BodyContent));
end;

procedure GetCustomerSelectedFieldsAsJSONObject(Customer: Record Customer; SlectedFields: List of [Integer]): JsonObject
var
    SerializationUtil: Codeunit SULSerializationUtilNVX;    
    JObject: JsonObject;
    BodyContent: Text;
begin
    BodyContent := SerializationUtil.Serialize(Customer, Enum::SULSerializerTypeNVX::JSON, SelectedFields, Enum::SULSerializableTypeNVX::Record);
    exit(JObject.WriteTo(BodyContent));
end;

JSON Deserialization of Records

local procedure UpdateCustomerFromApi(CustomerNo: Code[20]; Response: Text)
var
    Customer: Record Customer;
    ThrowError: Codeunit AppThrowErrorNVX;
    SerializationUtil: Codeunit SULSerializationUtilNVX;
    JsonFieldMapping: Dictionary of [Integer, Text];
    DeserializationFailed: List of [Text];
    Json: JsonObject;
begin
    //JsonFieldMapping consists of the Field No. of the BC Record as key and the respective Json Token from the response as value
    //DeserializationFailed contains the Json Tokens which must be deserialized manually

    ThrowError.IfCustomerDoesNotExist(Customer, CustomerNo);
    JsonFieldMapping.Add(2, 'name');
    JsonFieldMapping.Add(4, 'name2');

    Json.ReadFrom(Response);
    SerializationUtil.Deserialize(
        Json,
        MKSHeader,
        Enum::SULDeserializerTypeNVX::JSON,
        JsonFieldMapping,
        DeserializationFailed);
end;


Submit feedback for
DE|EN Imprint
<>